blob: 723a5c52ff32842d030d376c2e06940669870028 [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
Dian Xianga4928832015-09-15 10:11:17 -070011#include "common/BitSetIterator.h"
Jamie Madill437d2662014-12-05 14:23:35 -050012#include "common/utilities.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050013#include "libANGLE/Framebuffer.h"
14#include "libANGLE/FramebufferAttachment.h"
15#include "libANGLE/Program.h"
Jamie Madill53ea9cc2016-05-17 10:12:52 -040016#include "libANGLE/Uniform.h"
Jamie Madilld3dfda22015-07-06 08:28:49 -040017#include "libANGLE/VertexArray.h"
Jamie Madill6df9b372015-02-18 21:28:19 +000018#include "libANGLE/features.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050019#include "libANGLE/renderer/d3d/DynamicHLSL.h"
Jamie Madill85a18042015-03-05 15:41:41 -050020#include "libANGLE/renderer/d3d/FramebufferD3D.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050021#include "libANGLE/renderer/d3d/RendererD3D.h"
22#include "libANGLE/renderer/d3d/ShaderD3D.h"
Geoff Lang359ef262015-01-05 14:42:29 -050023#include "libANGLE/renderer/d3d/ShaderExecutableD3D.h"
Jamie Madill65345da2015-11-13 11:25:23 -050024#include "libANGLE/renderer/d3d/VaryingPacking.h"
Jamie Madill437d2662014-12-05 14:23:35 -050025#include "libANGLE/renderer/d3d/VertexDataManager.h"
Geoff Lang22072132014-11-20 15:15:01 -050026
Jamie Madill01074252016-11-28 15:55:51 -050027using namespace angle;
28
Brandon Jonesc9610c52014-08-25 17:02:59 -070029namespace rx
30{
31
Brandon Joneseb994362014-09-24 10:27:28 -070032namespace
33{
34
Jamie Madillf8dd7b12015-08-05 13:50:08 -040035gl::InputLayout GetDefaultInputLayoutFromShader(const gl::Shader *vertexShader)
Brandon Joneseb994362014-09-24 10:27:28 -070036{
Jamie Madillbd136f92015-08-10 14:51:37 -040037 gl::InputLayout defaultLayout;
38 for (const sh::Attribute &shaderAttr : vertexShader->getActiveAttributes())
Brandon Joneseb994362014-09-24 10:27:28 -070039 {
Brandon Joneseb994362014-09-24 10:27:28 -070040 if (shaderAttr.type != GL_NONE)
41 {
42 GLenum transposedType = gl::TransposeMatrixType(shaderAttr.type);
43
Jamie Madilld3dfda22015-07-06 08:28:49 -040044 for (size_t rowIndex = 0;
Jamie Madill334d6152015-10-22 14:00:28 -040045 static_cast<int>(rowIndex) < gl::VariableRowCount(transposedType); ++rowIndex)
Brandon Joneseb994362014-09-24 10:27:28 -070046 {
Jamie Madilld3dfda22015-07-06 08:28:49 -040047 GLenum componentType = gl::VariableComponentType(transposedType);
Jamie Madill334d6152015-10-22 14:00:28 -040048 GLuint components = static_cast<GLuint>(gl::VariableColumnCount(transposedType));
Jamie Madilld3dfda22015-07-06 08:28:49 -040049 bool pureInt = (componentType != GL_FLOAT);
Jamie Madill334d6152015-10-22 14:00:28 -040050 gl::VertexFormatType defaultType =
51 gl::GetVertexFormatType(componentType, GL_FALSE, components, pureInt);
Brandon Joneseb994362014-09-24 10:27:28 -070052
Jamie Madillbd136f92015-08-10 14:51:37 -040053 defaultLayout.push_back(defaultType);
Brandon Joneseb994362014-09-24 10:27:28 -070054 }
55 }
56 }
Jamie Madillf8dd7b12015-08-05 13:50:08 -040057
58 return defaultLayout;
Brandon Joneseb994362014-09-24 10:27:28 -070059}
60
Jamie Madill334d6152015-10-22 14:00:28 -040061std::vector<GLenum> GetDefaultOutputLayoutFromShader(
62 const std::vector<PixelShaderOutputVariable> &shaderOutputVars)
Brandon Joneseb994362014-09-24 10:27:28 -070063{
Jamie Madillb4463142014-12-19 14:56:54 -050064 std::vector<GLenum> defaultPixelOutput;
Brandon Joneseb994362014-09-24 10:27:28 -070065
Jamie Madillb4463142014-12-19 14:56:54 -050066 if (!shaderOutputVars.empty())
67 {
Cooper Partin4d61f7e2015-08-12 10:56:50 -070068 defaultPixelOutput.push_back(GL_COLOR_ATTACHMENT0 +
69 static_cast<unsigned int>(shaderOutputVars[0].outputIndex));
Jamie Madillb4463142014-12-19 14:56:54 -050070 }
Brandon Joneseb994362014-09-24 10:27:28 -070071
72 return defaultPixelOutput;
73}
74
Brandon Jones1a8a7e32014-10-01 12:49:30 -070075bool IsRowMajorLayout(const sh::InterfaceBlockField &var)
76{
77 return var.isRowMajorLayout;
78}
79
80bool IsRowMajorLayout(const sh::ShaderVariable &var)
81{
82 return false;
83}
84
Jamie Madill9fc36822015-11-18 13:08:07 -050085// true if varying x has a higher priority in packing than y
86bool ComparePackedVarying(const PackedVarying &x, const PackedVarying &y)
87{
Jamie Madill55c25d02015-11-18 13:08:08 -050088 return gl::CompareShaderVar(*x.varying, *y.varying);
Jamie Madill9fc36822015-11-18 13:08:07 -050089}
90
Jamie Madillca03b352015-09-02 12:38:13 -040091std::vector<PackedVarying> MergeVaryings(const gl::Shader &vertexShader,
92 const gl::Shader &fragmentShader,
93 const std::vector<std::string> &tfVaryings)
Jamie Madillada9ecc2015-08-17 12:53:37 -040094{
Jamie Madillca03b352015-09-02 12:38:13 -040095 std::vector<PackedVarying> packedVaryings;
96
97 for (const sh::Varying &output : vertexShader.getVaryings())
Jamie Madillada9ecc2015-08-17 12:53:37 -040098 {
Jamie Madillca03b352015-09-02 12:38:13 -040099 bool packed = false;
Jamie Madillada9ecc2015-08-17 12:53:37 -0400100
101 // Built-in varyings obey special rules
Jamie Madillca03b352015-09-02 12:38:13 -0400102 if (output.isBuiltIn())
Jamie Madillada9ecc2015-08-17 12:53:37 -0400103 {
104 continue;
105 }
106
Jamie Madillca03b352015-09-02 12:38:13 -0400107 for (const sh::Varying &input : fragmentShader.getVaryings())
Jamie Madillada9ecc2015-08-17 12:53:37 -0400108 {
Jamie Madillca03b352015-09-02 12:38:13 -0400109 if (output.name == input.name)
Jamie Madillada9ecc2015-08-17 12:53:37 -0400110 {
Jamie Madill55c25d02015-11-18 13:08:08 -0500111 if (output.isStruct())
112 {
113 ASSERT(!output.isArray());
114 for (const auto &field : output.fields)
115 {
116 ASSERT(!field.isStruct() && !field.isArray());
117 packedVaryings.push_back(
118 PackedVarying(field, input.interpolation, input.name));
119 }
120 }
121 else
122 {
123 packedVaryings.push_back(PackedVarying(input, input.interpolation));
124 }
Jamie Madillca03b352015-09-02 12:38:13 -0400125 packed = true;
Jamie Madillada9ecc2015-08-17 12:53:37 -0400126 break;
127 }
128 }
129
Jamie Madillca03b352015-09-02 12:38:13 -0400130 // Keep Transform FB varyings in the merged list always.
131 if (!packed)
132 {
133 for (const std::string &tfVarying : tfVaryings)
134 {
135 if (tfVarying == output.name)
136 {
Jamie Madill55c25d02015-11-18 13:08:08 -0500137 // Transform feedback for varying structs is underspecified.
138 // See Khronos bug 9856.
139 // TODO(jmadill): Figure out how to be spec-compliant here.
140 if (!output.isStruct())
141 {
142 packedVaryings.push_back(PackedVarying(output, output.interpolation));
143 packedVaryings.back().vertexOnly = true;
144 }
Jamie Madillca03b352015-09-02 12:38:13 -0400145 break;
146 }
147 }
148 }
Jamie Madillada9ecc2015-08-17 12:53:37 -0400149 }
150
Jamie Madill9fc36822015-11-18 13:08:07 -0500151 std::sort(packedVaryings.begin(), packedVaryings.end(), ComparePackedVarying);
152
Jamie Madillca03b352015-09-02 12:38:13 -0400153 return packedVaryings;
Brandon Joneseb994362014-09-24 10:27:28 -0700154}
155
Jamie Madill62d31cb2015-09-11 13:25:51 -0400156template <typename VarT>
157void GetUniformBlockInfo(const std::vector<VarT> &fields,
158 const std::string &prefix,
159 sh::BlockLayoutEncoder *encoder,
160 bool inRowMajorLayout,
161 std::map<std::string, sh::BlockMemberInfo> *blockInfoOut)
162{
163 for (const VarT &field : fields)
164 {
165 const std::string &fieldName = (prefix.empty() ? field.name : prefix + "." + field.name);
166
167 if (field.isStruct())
168 {
169 bool rowMajorLayout = (inRowMajorLayout || IsRowMajorLayout(field));
170
171 for (unsigned int arrayElement = 0; arrayElement < field.elementCount(); arrayElement++)
172 {
173 encoder->enterAggregateType();
174
175 const std::string uniformElementName =
176 fieldName + (field.isArray() ? ArrayString(arrayElement) : "");
177 GetUniformBlockInfo(field.fields, uniformElementName, encoder, rowMajorLayout,
178 blockInfoOut);
179
180 encoder->exitAggregateType();
181 }
182 }
183 else
184 {
185 bool isRowMajorMatrix = (gl::IsMatrixType(field.type) && inRowMajorLayout);
186 (*blockInfoOut)[fieldName] =
187 encoder->encodeType(field.type, field.arraySize, isRowMajorMatrix);
188 }
189 }
190}
191
Jamie Madill334d6152015-10-22 14:00:28 -0400192template <typename T>
Jacek Caban2302e692015-12-01 12:44:43 +0100193static inline void SetIfDirty(T *dest, const T &source, bool *dirtyFlag)
194{
195 ASSERT(dest != NULL);
196 ASSERT(dirtyFlag != NULL);
197
198 *dirtyFlag = *dirtyFlag || (memcmp(dest, &source, sizeof(T)) != 0);
199 *dest = source;
200}
201
202template <typename T>
Jamie Madill334d6152015-10-22 14:00:28 -0400203bool TransposeMatrix(T *target,
204 const GLfloat *value,
205 int targetWidth,
206 int targetHeight,
207 int srcWidth,
208 int srcHeight)
209{
210 bool dirty = false;
211 int copyWidth = std::min(targetHeight, srcWidth);
212 int copyHeight = std::min(targetWidth, srcHeight);
213
214 for (int x = 0; x < copyWidth; x++)
215 {
216 for (int y = 0; y < copyHeight; y++)
217 {
218 SetIfDirty(target + (x * targetWidth + y), static_cast<T>(value[y * srcWidth + x]),
219 &dirty);
220 }
221 }
222 // clear unfilled right side
223 for (int y = 0; y < copyWidth; y++)
224 {
225 for (int x = copyHeight; x < targetWidth; x++)
226 {
227 SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
228 }
229 }
230 // clear unfilled bottom.
231 for (int y = copyWidth; y < targetHeight; y++)
232 {
233 for (int x = 0; x < targetWidth; x++)
234 {
235 SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
236 }
237 }
238
239 return dirty;
240}
241
242template <typename T>
243bool ExpandMatrix(T *target,
244 const GLfloat *value,
245 int targetWidth,
246 int targetHeight,
247 int srcWidth,
248 int srcHeight)
249{
250 bool dirty = false;
251 int copyWidth = std::min(targetWidth, srcWidth);
252 int copyHeight = std::min(targetHeight, srcHeight);
253
254 for (int y = 0; y < copyHeight; y++)
255 {
256 for (int x = 0; x < copyWidth; x++)
257 {
258 SetIfDirty(target + (y * targetWidth + x), static_cast<T>(value[y * srcWidth + x]),
259 &dirty);
260 }
261 }
262 // clear unfilled right side
263 for (int y = 0; y < copyHeight; y++)
264 {
265 for (int x = copyWidth; x < targetWidth; x++)
266 {
267 SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
268 }
269 }
270 // clear unfilled bottom.
271 for (int y = copyHeight; y < targetHeight; y++)
272 {
273 for (int x = 0; x < targetWidth; x++)
274 {
275 SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
276 }
277 }
278
279 return dirty;
280}
281
Jamie Madill4e31ad52015-10-29 10:32:57 -0400282gl::PrimitiveType GetGeometryShaderTypeFromDrawMode(GLenum drawMode)
283{
284 switch (drawMode)
285 {
286 // Uses the point sprite geometry shader.
287 case GL_POINTS:
288 return gl::PRIMITIVE_POINTS;
289
290 // All line drawing uses the same geometry shader.
291 case GL_LINES:
292 case GL_LINE_STRIP:
293 case GL_LINE_LOOP:
294 return gl::PRIMITIVE_LINES;
295
296 // The triangle fan primitive is emulated with strips in D3D11.
297 case GL_TRIANGLES:
298 case GL_TRIANGLE_FAN:
299 return gl::PRIMITIVE_TRIANGLES;
300
301 // Special case for triangle strips.
302 case GL_TRIANGLE_STRIP:
303 return gl::PRIMITIVE_TRIANGLE_STRIP;
304
305 default:
306 UNREACHABLE();
307 return gl::PRIMITIVE_TYPE_MAX;
308 }
309}
310
Jamie Madillada9ecc2015-08-17 12:53:37 -0400311} // anonymous namespace
312
Jamie Madill28afae52015-11-09 15:07:57 -0500313// D3DUniform Implementation
314
Jamie Madill62d31cb2015-09-11 13:25:51 -0400315D3DUniform::D3DUniform(GLenum typeIn,
316 const std::string &nameIn,
317 unsigned int arraySizeIn,
318 bool defaultBlock)
319 : type(typeIn),
320 name(nameIn),
321 arraySize(arraySizeIn),
322 data(nullptr),
323 dirty(true),
Jamie Madill62d31cb2015-09-11 13:25:51 -0400324 vsRegisterIndex(GL_INVALID_INDEX),
Geoff Lang98c56da2015-09-15 15:45:34 -0400325 psRegisterIndex(GL_INVALID_INDEX),
Jamie Madill62d31cb2015-09-11 13:25:51 -0400326 registerCount(0),
327 registerElement(0)
328{
329 // We use data storage for default block uniforms to cache values that are sent to D3D during
330 // rendering
331 // Uniform blocks/buffers are treated separately by the Renderer (ES3 path only)
332 if (defaultBlock)
333 {
334 size_t bytes = gl::VariableInternalSize(type) * elementCount();
335 data = new uint8_t[bytes];
336 memset(data, 0, bytes);
337
338 // TODO(jmadill): is this correct with non-square matrices?
339 registerCount = gl::VariableRowCount(type) * elementCount();
340 }
341}
342
343D3DUniform::~D3DUniform()
344{
345 SafeDeleteArray(data);
346}
347
348bool D3DUniform::isSampler() const
349{
350 return gl::IsSamplerType(type);
351}
352
353bool D3DUniform::isReferencedByVertexShader() const
354{
355 return vsRegisterIndex != GL_INVALID_INDEX;
356}
357
358bool D3DUniform::isReferencedByFragmentShader() const
359{
360 return psRegisterIndex != GL_INVALID_INDEX;
361}
362
Jamie Madill28afae52015-11-09 15:07:57 -0500363// D3DVarying Implementation
364
Jamie Madill9fc36822015-11-18 13:08:07 -0500365D3DVarying::D3DVarying() : semanticIndex(0), componentCount(0), outputSlot(0)
Jamie Madill28afae52015-11-09 15:07:57 -0500366{
367}
368
Jamie Madill9fc36822015-11-18 13:08:07 -0500369D3DVarying::D3DVarying(const std::string &semanticNameIn,
370 unsigned int semanticIndexIn,
371 unsigned int componentCountIn,
372 unsigned int outputSlotIn)
373 : semanticName(semanticNameIn),
374 semanticIndex(semanticIndexIn),
375 componentCount(componentCountIn),
376 outputSlot(outputSlotIn)
Jamie Madill28afae52015-11-09 15:07:57 -0500377{
378}
379
Jamie Madille39a3f02015-11-17 20:42:15 -0500380// ProgramD3DMetadata Implementation
381
Jamie Madillc9bde922016-07-24 17:58:50 -0400382ProgramD3DMetadata::ProgramD3DMetadata(RendererD3D *renderer,
Jamie Madille39a3f02015-11-17 20:42:15 -0500383 const ShaderD3D *vertexShader,
384 const ShaderD3D *fragmentShader)
Jamie Madillc9bde922016-07-24 17:58:50 -0400385 : mRendererMajorShaderModel(renderer->getMajorShaderModel()),
386 mShaderModelSuffix(renderer->getShaderModelSuffix()),
387 mUsesInstancedPointSpriteEmulation(
388 renderer->getWorkarounds().useInstancedPointSpriteEmulation),
389 mUsesViewScale(renderer->presentPathFastEnabled()),
Jamie Madille39a3f02015-11-17 20:42:15 -0500390 mVertexShader(vertexShader),
391 mFragmentShader(fragmentShader)
392{
393}
394
395int ProgramD3DMetadata::getRendererMajorShaderModel() const
396{
397 return mRendererMajorShaderModel;
398}
399
Jamie Madill9082b982016-04-27 15:21:51 -0400400bool ProgramD3DMetadata::usesBroadcast(const gl::ContextState &data) const
Jamie Madille39a3f02015-11-17 20:42:15 -0500401{
Martin Radev1be913c2016-07-11 17:59:16 +0300402 return (mFragmentShader->usesFragColor() && data.getClientMajorVersion() < 3);
Jamie Madille39a3f02015-11-17 20:42:15 -0500403}
404
Jamie Madill48ef11b2016-04-27 15:21:52 -0400405bool ProgramD3DMetadata::usesFragDepth() const
Jamie Madille39a3f02015-11-17 20:42:15 -0500406{
Jamie Madill63286672015-11-24 13:00:08 -0500407 return mFragmentShader->usesFragDepth();
Jamie Madille39a3f02015-11-17 20:42:15 -0500408}
409
410bool ProgramD3DMetadata::usesPointCoord() const
411{
412 return mFragmentShader->usesPointCoord();
413}
414
415bool ProgramD3DMetadata::usesFragCoord() const
416{
417 return mFragmentShader->usesFragCoord();
418}
419
420bool ProgramD3DMetadata::usesPointSize() const
421{
422 return mVertexShader->usesPointSize();
423}
424
425bool ProgramD3DMetadata::usesInsertedPointCoordValue() const
426{
Jamie Madillc9bde922016-07-24 17:58:50 -0400427 return (!usesPointSize() || !mUsesInstancedPointSpriteEmulation) && usesPointCoord() &&
428 mRendererMajorShaderModel >= 4;
Jamie Madille39a3f02015-11-17 20:42:15 -0500429}
430
Austin Kinross2a63b3f2016-02-08 12:29:08 -0800431bool ProgramD3DMetadata::usesViewScale() const
432{
433 return mUsesViewScale;
434}
435
Jamie Madille39a3f02015-11-17 20:42:15 -0500436bool ProgramD3DMetadata::addsPointCoordToVertexShader() const
437{
Jamie Madillc9bde922016-07-24 17:58:50 -0400438 // PointSprite emulation requiress that gl_PointCoord is present in the vertex shader
Jamie Madille39a3f02015-11-17 20:42:15 -0500439 // VS_OUTPUT structure to ensure compatibility with the generated PS_INPUT of the pixel shader.
Jamie Madillc9bde922016-07-24 17:58:50 -0400440 // Even with a geometry shader, the app can render triangles or lines and reference
441 // gl_PointCoord in the fragment shader, requiring us to provide a dummy value. For
442 // simplicity, we always add this to the vertex shader when the fragment shader
443 // references gl_PointCoord, even if we could skip it in the geometry shader.
Jamie Madille39a3f02015-11-17 20:42:15 -0500444 return (mUsesInstancedPointSpriteEmulation && usesPointCoord()) ||
445 usesInsertedPointCoordValue();
446}
447
448bool ProgramD3DMetadata::usesTransformFeedbackGLPosition() const
449{
450 // gl_Position only needs to be outputted from the vertex shader if transform feedback is
451 // active. This isn't supported on D3D11 Feature Level 9_3, so we don't output gl_Position from
452 // the vertex shader in this case. This saves us 1 output vector.
453 return !(mRendererMajorShaderModel >= 4 && mShaderModelSuffix != "");
454}
455
456bool ProgramD3DMetadata::usesSystemValuePointSize() const
457{
458 return !mUsesInstancedPointSpriteEmulation && usesPointSize();
459}
460
461bool ProgramD3DMetadata::usesMultipleFragmentOuts() const
462{
463 return mFragmentShader->usesMultipleRenderTargets();
464}
465
466GLint ProgramD3DMetadata::getMajorShaderVersion() const
467{
468 return mVertexShader->getData().getShaderVersion();
469}
470
471const ShaderD3D *ProgramD3DMetadata::getFragmentShader() const
472{
473 return mFragmentShader;
474}
475
Jamie Madill28afae52015-11-09 15:07:57 -0500476// ProgramD3D Implementation
477
Jamie Madilld3dfda22015-07-06 08:28:49 -0400478ProgramD3D::VertexExecutable::VertexExecutable(const gl::InputLayout &inputLayout,
479 const Signature &signature,
Geoff Lang359ef262015-01-05 14:42:29 -0500480 ShaderExecutableD3D *shaderExecutable)
Jamie Madill334d6152015-10-22 14:00:28 -0400481 : mInputs(inputLayout), mSignature(signature), mShaderExecutable(shaderExecutable)
Brandon Joneseb994362014-09-24 10:27:28 -0700482{
Brandon Joneseb994362014-09-24 10:27:28 -0700483}
484
485ProgramD3D::VertexExecutable::~VertexExecutable()
486{
487 SafeDelete(mShaderExecutable);
488}
489
Jamie Madilld3dfda22015-07-06 08:28:49 -0400490// static
Jamie Madillbdec2f42016-03-02 16:35:32 -0500491ProgramD3D::VertexExecutable::HLSLAttribType ProgramD3D::VertexExecutable::GetAttribType(
492 GLenum type)
493{
494 switch (type)
495 {
496 case GL_INT:
497 return HLSLAttribType::SIGNED_INT;
498 case GL_UNSIGNED_INT:
499 return HLSLAttribType::UNSIGNED_INT;
500 case GL_SIGNED_NORMALIZED:
501 case GL_UNSIGNED_NORMALIZED:
502 case GL_FLOAT:
503 return HLSLAttribType::FLOAT;
504 default:
505 UNREACHABLE();
506 return HLSLAttribType::FLOAT;
507 }
508}
509
510// static
Jamie Madilld3dfda22015-07-06 08:28:49 -0400511void ProgramD3D::VertexExecutable::getSignature(RendererD3D *renderer,
512 const gl::InputLayout &inputLayout,
513 Signature *signatureOut)
Brandon Joneseb994362014-09-24 10:27:28 -0700514{
Jamie Madillbdec2f42016-03-02 16:35:32 -0500515 signatureOut->assign(inputLayout.size(), HLSLAttribType::FLOAT);
Jamie Madilld3dfda22015-07-06 08:28:49 -0400516
517 for (size_t index = 0; index < inputLayout.size(); ++index)
Brandon Joneseb994362014-09-24 10:27:28 -0700518 {
Jamie Madilld3dfda22015-07-06 08:28:49 -0400519 gl::VertexFormatType vertexFormatType = inputLayout[index];
Jamie Madillbdec2f42016-03-02 16:35:32 -0500520 if (vertexFormatType == gl::VERTEX_FORMAT_INVALID)
521 continue;
Jamie Madillbd136f92015-08-10 14:51:37 -0400522
Jamie Madillbdec2f42016-03-02 16:35:32 -0500523 VertexConversionType conversionType = renderer->getVertexConversionType(vertexFormatType);
524 if ((conversionType & VERTEX_CONVERT_GPU) == 0)
525 continue;
526
527 GLenum componentType = renderer->getVertexComponentType(vertexFormatType);
528 (*signatureOut)[index] = GetAttribType(componentType);
Brandon Joneseb994362014-09-24 10:27:28 -0700529 }
Brandon Joneseb994362014-09-24 10:27:28 -0700530}
531
Jamie Madilld3dfda22015-07-06 08:28:49 -0400532bool ProgramD3D::VertexExecutable::matchesSignature(const Signature &signature) const
533{
Jamie Madillbd136f92015-08-10 14:51:37 -0400534 size_t limit = std::max(mSignature.size(), signature.size());
535 for (size_t index = 0; index < limit; ++index)
536 {
Jamie Madillbdec2f42016-03-02 16:35:32 -0500537 // treat undefined indexes as FLOAT
538 auto a = index < signature.size() ? signature[index] : HLSLAttribType::FLOAT;
539 auto b = index < mSignature.size() ? mSignature[index] : HLSLAttribType::FLOAT;
Jamie Madillbd136f92015-08-10 14:51:37 -0400540 if (a != b)
541 return false;
542 }
543
544 return true;
Jamie Madilld3dfda22015-07-06 08:28:49 -0400545}
546
547ProgramD3D::PixelExecutable::PixelExecutable(const std::vector<GLenum> &outputSignature,
548 ShaderExecutableD3D *shaderExecutable)
Jamie Madill334d6152015-10-22 14:00:28 -0400549 : mOutputSignature(outputSignature), mShaderExecutable(shaderExecutable)
Brandon Joneseb994362014-09-24 10:27:28 -0700550{
551}
552
553ProgramD3D::PixelExecutable::~PixelExecutable()
554{
555 SafeDelete(mShaderExecutable);
556}
557
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700558ProgramD3D::Sampler::Sampler() : active(false), logicalTextureUnit(0), textureType(GL_TEXTURE_2D)
559{
560}
561
Geoff Lang7dd2e102014-11-10 15:19:26 -0500562unsigned int ProgramD3D::mCurrentSerial = 1;
563
Jamie Madill48ef11b2016-04-27 15:21:52 -0400564ProgramD3D::ProgramD3D(const gl::ProgramState &state, RendererD3D *renderer)
565 : ProgramImpl(state),
Brandon Jonesc9610c52014-08-25 17:02:59 -0700566 mRenderer(renderer),
567 mDynamicHLSL(NULL),
Jamie Madill4e31ad52015-10-29 10:32:57 -0400568 mGeometryExecutables(gl::PRIMITIVE_TYPE_MAX, nullptr),
Brandon Jones44151a92014-09-10 11:32:25 -0700569 mUsesPointSize(false),
Jamie Madill3e14e2b2015-10-29 14:38:53 -0400570 mUsesFlatInterpolation(false),
Brandon Jonesc9610c52014-08-25 17:02:59 -0700571 mVertexUniformStorage(NULL),
Brandon Jones44151a92014-09-10 11:32:25 -0700572 mFragmentUniformStorage(NULL),
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700573 mUsedVertexSamplerRange(0),
574 mUsedPixelSamplerRange(0),
575 mDirtySamplerMapping(true),
Geoff Lang7dd2e102014-11-10 15:19:26 -0500576 mSerial(issueSerial())
Brandon Jonesc9610c52014-08-25 17:02:59 -0700577{
Brandon Joneseb994362014-09-24 10:27:28 -0700578 mDynamicHLSL = new DynamicHLSL(renderer);
Brandon Jonesc9610c52014-08-25 17:02:59 -0700579}
580
581ProgramD3D::~ProgramD3D()
582{
583 reset();
584 SafeDelete(mDynamicHLSL);
585}
586
Brandon Jones44151a92014-09-10 11:32:25 -0700587bool ProgramD3D::usesPointSpriteEmulation() const
588{
589 return mUsesPointSize && mRenderer->getMajorShaderModel() >= 4;
590}
591
Jamie Madill3e14e2b2015-10-29 14:38:53 -0400592bool ProgramD3D::usesGeometryShader(GLenum drawMode) const
Brandon Jones44151a92014-09-10 11:32:25 -0700593{
Jamie Madill3e14e2b2015-10-29 14:38:53 -0400594 if (drawMode != GL_POINTS)
595 {
596 return mUsesFlatInterpolation;
597 }
598
Cooper Partine6664f02015-01-09 16:22:24 -0800599 return usesPointSpriteEmulation() && !usesInstancedPointSpriteEmulation();
600}
601
602bool ProgramD3D::usesInstancedPointSpriteEmulation() const
603{
604 return mRenderer->getWorkarounds().useInstancedPointSpriteEmulation;
Brandon Jones44151a92014-09-10 11:32:25 -0700605}
606
Jamie Madill334d6152015-10-22 14:00:28 -0400607GLint ProgramD3D::getSamplerMapping(gl::SamplerType type,
608 unsigned int samplerIndex,
609 const gl::Caps &caps) const
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700610{
611 GLint logicalTextureUnit = -1;
612
613 switch (type)
614 {
Jamie Madill334d6152015-10-22 14:00:28 -0400615 case gl::SAMPLER_PIXEL:
616 ASSERT(samplerIndex < caps.maxTextureImageUnits);
617 if (samplerIndex < mSamplersPS.size() && mSamplersPS[samplerIndex].active)
618 {
619 logicalTextureUnit = mSamplersPS[samplerIndex].logicalTextureUnit;
620 }
621 break;
622 case gl::SAMPLER_VERTEX:
623 ASSERT(samplerIndex < caps.maxVertexTextureImageUnits);
624 if (samplerIndex < mSamplersVS.size() && mSamplersVS[samplerIndex].active)
625 {
626 logicalTextureUnit = mSamplersVS[samplerIndex].logicalTextureUnit;
627 }
628 break;
629 default:
630 UNREACHABLE();
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700631 }
632
Jamie Madill334d6152015-10-22 14:00:28 -0400633 if (logicalTextureUnit >= 0 &&
634 logicalTextureUnit < static_cast<GLint>(caps.maxCombinedTextureImageUnits))
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700635 {
636 return logicalTextureUnit;
637 }
638
639 return -1;
640}
641
642// Returns the texture type for a given Direct3D 9 sampler type and
643// index (0-15 for the pixel shader and 0-3 for the vertex shader).
644GLenum ProgramD3D::getSamplerTextureType(gl::SamplerType type, unsigned int samplerIndex) const
645{
646 switch (type)
647 {
Jamie Madill334d6152015-10-22 14:00:28 -0400648 case gl::SAMPLER_PIXEL:
649 ASSERT(samplerIndex < mSamplersPS.size());
650 ASSERT(mSamplersPS[samplerIndex].active);
651 return mSamplersPS[samplerIndex].textureType;
652 case gl::SAMPLER_VERTEX:
653 ASSERT(samplerIndex < mSamplersVS.size());
654 ASSERT(mSamplersVS[samplerIndex].active);
655 return mSamplersVS[samplerIndex].textureType;
656 default:
657 UNREACHABLE();
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700658 }
659
660 return GL_TEXTURE_2D;
661}
662
Olli Etuaho618bebc2016-01-15 16:40:00 +0200663GLuint ProgramD3D::getUsedSamplerRange(gl::SamplerType type) const
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700664{
665 switch (type)
666 {
Jamie Madill334d6152015-10-22 14:00:28 -0400667 case gl::SAMPLER_PIXEL:
668 return mUsedPixelSamplerRange;
669 case gl::SAMPLER_VERTEX:
670 return mUsedVertexSamplerRange;
671 default:
672 UNREACHABLE();
Olli Etuaho618bebc2016-01-15 16:40:00 +0200673 return 0u;
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700674 }
675}
676
677void ProgramD3D::updateSamplerMapping()
678{
679 if (!mDirtySamplerMapping)
680 {
681 return;
682 }
683
684 mDirtySamplerMapping = false;
685
686 // Retrieve sampler uniform values
Jamie Madill62d31cb2015-09-11 13:25:51 -0400687 for (const D3DUniform *d3dUniform : mD3DUniforms)
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700688 {
Jamie Madill62d31cb2015-09-11 13:25:51 -0400689 if (!d3dUniform->dirty)
690 continue;
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700691
Jamie Madill62d31cb2015-09-11 13:25:51 -0400692 if (!d3dUniform->isSampler())
693 continue;
694
695 int count = d3dUniform->elementCount();
696 const GLint(*v)[4] = reinterpret_cast<const GLint(*)[4]>(d3dUniform->data);
697
698 if (d3dUniform->isReferencedByFragmentShader())
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700699 {
Jamie Madill62d31cb2015-09-11 13:25:51 -0400700 unsigned int firstIndex = d3dUniform->psRegisterIndex;
701
702 for (int i = 0; i < count; i++)
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700703 {
Jamie Madill62d31cb2015-09-11 13:25:51 -0400704 unsigned int samplerIndex = firstIndex + i;
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700705
Jamie Madill62d31cb2015-09-11 13:25:51 -0400706 if (samplerIndex < mSamplersPS.size())
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700707 {
Jamie Madill62d31cb2015-09-11 13:25:51 -0400708 ASSERT(mSamplersPS[samplerIndex].active);
709 mSamplersPS[samplerIndex].logicalTextureUnit = v[i][0];
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700710 }
Jamie Madill62d31cb2015-09-11 13:25:51 -0400711 }
712 }
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700713
Jamie Madill62d31cb2015-09-11 13:25:51 -0400714 if (d3dUniform->isReferencedByVertexShader())
715 {
716 unsigned int firstIndex = d3dUniform->vsRegisterIndex;
717
718 for (int i = 0; i < count; i++)
719 {
720 unsigned int samplerIndex = firstIndex + i;
721
722 if (samplerIndex < mSamplersVS.size())
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700723 {
Jamie Madill62d31cb2015-09-11 13:25:51 -0400724 ASSERT(mSamplersVS[samplerIndex].active);
725 mSamplersVS[samplerIndex].logicalTextureUnit = v[i][0];
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700726 }
727 }
728 }
729 }
730}
731
Geoff Lang7dd2e102014-11-10 15:19:26 -0500732LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
Brandon Jones22502d52014-08-29 16:58:36 -0700733{
Jamie Madill62d31cb2015-09-11 13:25:51 -0400734 reset();
735
Jamie Madill334d6152015-10-22 14:00:28 -0400736 DeviceIdentifier binaryDeviceIdentifier = {0};
737 stream->readBytes(reinterpret_cast<unsigned char *>(&binaryDeviceIdentifier),
738 sizeof(DeviceIdentifier));
Austin Kinross137b1512015-06-17 16:14:53 -0700739
740 DeviceIdentifier identifier = mRenderer->getAdapterIdentifier();
741 if (memcmp(&identifier, &binaryDeviceIdentifier, sizeof(DeviceIdentifier)) != 0)
742 {
743 infoLog << "Invalid program binary, device configuration has changed.";
Jamie Madillb0a838b2016-11-13 20:02:12 -0500744 return false;
Austin Kinross137b1512015-06-17 16:14:53 -0700745 }
746
Jamie Madill2db1fbb2014-12-03 10:58:55 -0500747 int compileFlags = stream->readInt<int>();
748 if (compileFlags != ANGLE_COMPILE_OPTIMIZATION_LEVEL)
749 {
Jamie Madillf6113162015-05-07 11:49:21 -0400750 infoLog << "Mismatched compilation flags.";
Jamie Madillb0a838b2016-11-13 20:02:12 -0500751 return false;
Jamie Madill2db1fbb2014-12-03 10:58:55 -0500752 }
753
Jamie Madill8047c0d2016-03-07 13:02:12 -0500754 for (int &index : mAttribLocationToD3DSemantic)
Jamie Madill63805b42015-08-25 13:17:39 -0400755 {
Jamie Madill8047c0d2016-03-07 13:02:12 -0500756 stream->readInt(&index);
Jamie Madill63805b42015-08-25 13:17:39 -0400757 }
758
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700759 const unsigned int psSamplerCount = stream->readInt<unsigned int>();
760 for (unsigned int i = 0; i < psSamplerCount; ++i)
761 {
762 Sampler sampler;
763 stream->readBool(&sampler.active);
764 stream->readInt(&sampler.logicalTextureUnit);
765 stream->readInt(&sampler.textureType);
766 mSamplersPS.push_back(sampler);
767 }
768 const unsigned int vsSamplerCount = stream->readInt<unsigned int>();
769 for (unsigned int i = 0; i < vsSamplerCount; ++i)
770 {
771 Sampler sampler;
772 stream->readBool(&sampler.active);
773 stream->readInt(&sampler.logicalTextureUnit);
774 stream->readInt(&sampler.textureType);
775 mSamplersVS.push_back(sampler);
776 }
777
778 stream->readInt(&mUsedVertexSamplerRange);
779 stream->readInt(&mUsedPixelSamplerRange);
780
781 const unsigned int uniformCount = stream->readInt<unsigned int>();
782 if (stream->error())
783 {
Jamie Madillf6113162015-05-07 11:49:21 -0400784 infoLog << "Invalid program binary.";
Jamie Madillb0a838b2016-11-13 20:02:12 -0500785 return false;
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700786 }
787
Jamie Madill48ef11b2016-04-27 15:21:52 -0400788 const auto &linkedUniforms = mState.getUniforms();
Jamie Madill62d31cb2015-09-11 13:25:51 -0400789 ASSERT(mD3DUniforms.empty());
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700790 for (unsigned int uniformIndex = 0; uniformIndex < uniformCount; uniformIndex++)
791 {
Jamie Madill62d31cb2015-09-11 13:25:51 -0400792 const gl::LinkedUniform &linkedUniform = linkedUniforms[uniformIndex];
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700793
Jamie Madill62d31cb2015-09-11 13:25:51 -0400794 D3DUniform *d3dUniform =
795 new D3DUniform(linkedUniform.type, linkedUniform.name, linkedUniform.arraySize,
796 linkedUniform.isInDefaultBlock());
797 stream->readInt(&d3dUniform->psRegisterIndex);
798 stream->readInt(&d3dUniform->vsRegisterIndex);
799 stream->readInt(&d3dUniform->registerCount);
800 stream->readInt(&d3dUniform->registerElement);
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700801
Jamie Madill62d31cb2015-09-11 13:25:51 -0400802 mD3DUniforms.push_back(d3dUniform);
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700803 }
804
Jamie Madill4a3c2342015-10-08 12:58:45 -0400805 const unsigned int blockCount = stream->readInt<unsigned int>();
806 if (stream->error())
807 {
808 infoLog << "Invalid program binary.";
Jamie Madillb0a838b2016-11-13 20:02:12 -0500809 return false;
Jamie Madill4a3c2342015-10-08 12:58:45 -0400810 }
811
812 ASSERT(mD3DUniformBlocks.empty());
813 for (unsigned int blockIndex = 0; blockIndex < blockCount; ++blockIndex)
814 {
815 D3DUniformBlock uniformBlock;
816 stream->readInt(&uniformBlock.psRegisterIndex);
817 stream->readInt(&uniformBlock.vsRegisterIndex);
818 mD3DUniformBlocks.push_back(uniformBlock);
819 }
820
Jamie Madill9fc36822015-11-18 13:08:07 -0500821 const unsigned int streamOutVaryingCount = stream->readInt<unsigned int>();
822 mStreamOutVaryings.resize(streamOutVaryingCount);
823 for (unsigned int varyingIndex = 0; varyingIndex < streamOutVaryingCount; ++varyingIndex)
Brandon Joneseb994362014-09-24 10:27:28 -0700824 {
Jamie Madill9fc36822015-11-18 13:08:07 -0500825 D3DVarying *varying = &mStreamOutVaryings[varyingIndex];
Brandon Joneseb994362014-09-24 10:27:28 -0700826
Jamie Madill28afae52015-11-09 15:07:57 -0500827 stream->readString(&varying->semanticName);
828 stream->readInt(&varying->semanticIndex);
Jamie Madill9fc36822015-11-18 13:08:07 -0500829 stream->readInt(&varying->componentCount);
830 stream->readInt(&varying->outputSlot);
Brandon Joneseb994362014-09-24 10:27:28 -0700831 }
832
Brandon Jones22502d52014-08-29 16:58:36 -0700833 stream->readString(&mVertexHLSL);
Jamie Madill334d6152015-10-22 14:00:28 -0400834 stream->readBytes(reinterpret_cast<unsigned char *>(&mVertexWorkarounds),
835 sizeof(D3DCompilerWorkarounds));
Brandon Jones22502d52014-08-29 16:58:36 -0700836 stream->readString(&mPixelHLSL);
Jamie Madill334d6152015-10-22 14:00:28 -0400837 stream->readBytes(reinterpret_cast<unsigned char *>(&mPixelWorkarounds),
838 sizeof(D3DCompilerWorkarounds));
Brandon Jones22502d52014-08-29 16:58:36 -0700839 stream->readBool(&mUsesFragDepth);
Brandon Jones44151a92014-09-10 11:32:25 -0700840 stream->readBool(&mUsesPointSize);
Jamie Madill3e14e2b2015-10-29 14:38:53 -0400841 stream->readBool(&mUsesFlatInterpolation);
Brandon Jones22502d52014-08-29 16:58:36 -0700842
843 const size_t pixelShaderKeySize = stream->readInt<unsigned int>();
844 mPixelShaderKey.resize(pixelShaderKeySize);
Jamie Madill334d6152015-10-22 14:00:28 -0400845 for (size_t pixelShaderKeyIndex = 0; pixelShaderKeyIndex < pixelShaderKeySize;
846 pixelShaderKeyIndex++)
Brandon Jones22502d52014-08-29 16:58:36 -0700847 {
848 stream->readInt(&mPixelShaderKey[pixelShaderKeyIndex].type);
849 stream->readString(&mPixelShaderKey[pixelShaderKeyIndex].name);
850 stream->readString(&mPixelShaderKey[pixelShaderKeyIndex].source);
851 stream->readInt(&mPixelShaderKey[pixelShaderKeyIndex].outputIndex);
852 }
853
Jamie Madill4e31ad52015-10-29 10:32:57 -0400854 stream->readString(&mGeometryShaderPreamble);
855
Jamie Madill334d6152015-10-22 14:00:28 -0400856 const unsigned char *binary = reinterpret_cast<const unsigned char *>(stream->data());
Brandon Joneseb994362014-09-24 10:27:28 -0700857
Jamie Madillb0a838b2016-11-13 20:02:12 -0500858 bool separateAttribs = (mState.getTransformFeedbackBufferMode() == GL_SEPARATE_ATTRIBS);
859
Brandon Joneseb994362014-09-24 10:27:28 -0700860 const unsigned int vertexShaderCount = stream->readInt<unsigned int>();
Jamie Madill334d6152015-10-22 14:00:28 -0400861 for (unsigned int vertexShaderIndex = 0; vertexShaderIndex < vertexShaderCount;
862 vertexShaderIndex++)
Brandon Joneseb994362014-09-24 10:27:28 -0700863 {
Jamie Madilld3dfda22015-07-06 08:28:49 -0400864 size_t inputLayoutSize = stream->readInt<size_t>();
Jamie Madillf8dd7b12015-08-05 13:50:08 -0400865 gl::InputLayout inputLayout(inputLayoutSize, gl::VERTEX_FORMAT_INVALID);
Brandon Joneseb994362014-09-24 10:27:28 -0700866
Jamie Madilld3dfda22015-07-06 08:28:49 -0400867 for (size_t inputIndex = 0; inputIndex < inputLayoutSize; inputIndex++)
Brandon Joneseb994362014-09-24 10:27:28 -0700868 {
Jamie Madillf8dd7b12015-08-05 13:50:08 -0400869 inputLayout[inputIndex] = stream->readInt<gl::VertexFormatType>();
Brandon Joneseb994362014-09-24 10:27:28 -0700870 }
871
Jamie Madill334d6152015-10-22 14:00:28 -0400872 unsigned int vertexShaderSize = stream->readInt<unsigned int>();
Brandon Joneseb994362014-09-24 10:27:28 -0700873 const unsigned char *vertexShaderFunction = binary + stream->offset();
Geoff Langb543aff2014-09-30 14:52:54 -0400874
Jamie Madillada9ecc2015-08-17 12:53:37 -0400875 ShaderExecutableD3D *shaderExecutable = nullptr;
876
Jamie Madillb0a838b2016-11-13 20:02:12 -0500877 ANGLE_TRY(mRenderer->loadExecutable(vertexShaderFunction, vertexShaderSize, SHADER_VERTEX,
878 mStreamOutVaryings, separateAttribs,
879 &shaderExecutable));
Geoff Langb543aff2014-09-30 14:52:54 -0400880
Brandon Joneseb994362014-09-24 10:27:28 -0700881 if (!shaderExecutable)
882 {
Jamie Madillf6113162015-05-07 11:49:21 -0400883 infoLog << "Could not create vertex shader.";
Jamie Madillb0a838b2016-11-13 20:02:12 -0500884 return false;
Brandon Joneseb994362014-09-24 10:27:28 -0700885 }
886
887 // generated converted input layout
Jamie Madilld3dfda22015-07-06 08:28:49 -0400888 VertexExecutable::Signature signature;
889 VertexExecutable::getSignature(mRenderer, inputLayout, &signature);
Brandon Joneseb994362014-09-24 10:27:28 -0700890
891 // add new binary
Jamie Madill334d6152015-10-22 14:00:28 -0400892 mVertexExecutables.push_back(
893 new VertexExecutable(inputLayout, signature, shaderExecutable));
Brandon Joneseb994362014-09-24 10:27:28 -0700894
895 stream->skip(vertexShaderSize);
896 }
897
898 const size_t pixelShaderCount = stream->readInt<unsigned int>();
899 for (size_t pixelShaderIndex = 0; pixelShaderIndex < pixelShaderCount; pixelShaderIndex++)
900 {
901 const size_t outputCount = stream->readInt<unsigned int>();
902 std::vector<GLenum> outputs(outputCount);
903 for (size_t outputIndex = 0; outputIndex < outputCount; outputIndex++)
904 {
905 stream->readInt(&outputs[outputIndex]);
906 }
907
Jamie Madill334d6152015-10-22 14:00:28 -0400908 const size_t pixelShaderSize = stream->readInt<unsigned int>();
Brandon Joneseb994362014-09-24 10:27:28 -0700909 const unsigned char *pixelShaderFunction = binary + stream->offset();
Jamie Madillada9ecc2015-08-17 12:53:37 -0400910 ShaderExecutableD3D *shaderExecutable = nullptr;
911
Jamie Madillb0a838b2016-11-13 20:02:12 -0500912 ANGLE_TRY(mRenderer->loadExecutable(pixelShaderFunction, pixelShaderSize, SHADER_PIXEL,
913 mStreamOutVaryings, separateAttribs,
914 &shaderExecutable));
Brandon Joneseb994362014-09-24 10:27:28 -0700915
916 if (!shaderExecutable)
917 {
Jamie Madillf6113162015-05-07 11:49:21 -0400918 infoLog << "Could not create pixel shader.";
Jamie Madillb0a838b2016-11-13 20:02:12 -0500919 return false;
Brandon Joneseb994362014-09-24 10:27:28 -0700920 }
921
922 // add new binary
923 mPixelExecutables.push_back(new PixelExecutable(outputs, shaderExecutable));
924
925 stream->skip(pixelShaderSize);
926 }
927
Jamie Madill4e31ad52015-10-29 10:32:57 -0400928 for (unsigned int geometryExeIndex = 0; geometryExeIndex < gl::PRIMITIVE_TYPE_MAX;
929 ++geometryExeIndex)
Brandon Joneseb994362014-09-24 10:27:28 -0700930 {
Jamie Madill4e31ad52015-10-29 10:32:57 -0400931 unsigned int geometryShaderSize = stream->readInt<unsigned int>();
932 if (geometryShaderSize == 0)
933 {
934 mGeometryExecutables[geometryExeIndex] = nullptr;
935 continue;
936 }
937
Brandon Joneseb994362014-09-24 10:27:28 -0700938 const unsigned char *geometryShaderFunction = binary + stream->offset();
Jamie Madill4e31ad52015-10-29 10:32:57 -0400939
Jamie Madillb0a838b2016-11-13 20:02:12 -0500940 ANGLE_TRY(mRenderer->loadExecutable(geometryShaderFunction, geometryShaderSize,
941 SHADER_GEOMETRY, mStreamOutVaryings, separateAttribs,
942 &mGeometryExecutables[geometryExeIndex]));
Brandon Joneseb994362014-09-24 10:27:28 -0700943
Jamie Madill4e31ad52015-10-29 10:32:57 -0400944 if (!mGeometryExecutables[geometryExeIndex])
Brandon Joneseb994362014-09-24 10:27:28 -0700945 {
Jamie Madillf6113162015-05-07 11:49:21 -0400946 infoLog << "Could not create geometry shader.";
Jamie Madillb0a838b2016-11-13 20:02:12 -0500947 return false;
Brandon Joneseb994362014-09-24 10:27:28 -0700948 }
949 stream->skip(geometryShaderSize);
950 }
951
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700952 initializeUniformStorage();
953
Jamie Madillb0a838b2016-11-13 20:02:12 -0500954 return true;
Brandon Jones22502d52014-08-29 16:58:36 -0700955}
956
Geoff Langb543aff2014-09-30 14:52:54 -0400957gl::Error ProgramD3D::save(gl::BinaryOutputStream *stream)
Brandon Jones22502d52014-08-29 16:58:36 -0700958{
Austin Kinross137b1512015-06-17 16:14:53 -0700959 // Output the DeviceIdentifier before we output any shader code
Jamie Madill334d6152015-10-22 14:00:28 -0400960 // When we load the binary again later, we can validate the device identifier before trying to
961 // compile any HLSL
Austin Kinross137b1512015-06-17 16:14:53 -0700962 DeviceIdentifier binaryIdentifier = mRenderer->getAdapterIdentifier();
Jamie Madill334d6152015-10-22 14:00:28 -0400963 stream->writeBytes(reinterpret_cast<unsigned char *>(&binaryIdentifier),
964 sizeof(DeviceIdentifier));
Austin Kinross137b1512015-06-17 16:14:53 -0700965
Jamie Madill2db1fbb2014-12-03 10:58:55 -0500966 stream->writeInt(ANGLE_COMPILE_OPTIMIZATION_LEVEL);
967
Jamie Madill8047c0d2016-03-07 13:02:12 -0500968 for (int d3dSemantic : mAttribLocationToD3DSemantic)
Jamie Madill63805b42015-08-25 13:17:39 -0400969 {
Jamie Madill8047c0d2016-03-07 13:02:12 -0500970 stream->writeInt(d3dSemantic);
Jamie Madill63805b42015-08-25 13:17:39 -0400971 }
972
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700973 stream->writeInt(mSamplersPS.size());
974 for (unsigned int i = 0; i < mSamplersPS.size(); ++i)
975 {
976 stream->writeInt(mSamplersPS[i].active);
977 stream->writeInt(mSamplersPS[i].logicalTextureUnit);
978 stream->writeInt(mSamplersPS[i].textureType);
979 }
980
981 stream->writeInt(mSamplersVS.size());
982 for (unsigned int i = 0; i < mSamplersVS.size(); ++i)
983 {
984 stream->writeInt(mSamplersVS[i].active);
985 stream->writeInt(mSamplersVS[i].logicalTextureUnit);
986 stream->writeInt(mSamplersVS[i].textureType);
987 }
988
989 stream->writeInt(mUsedVertexSamplerRange);
990 stream->writeInt(mUsedPixelSamplerRange);
991
Jamie Madill62d31cb2015-09-11 13:25:51 -0400992 stream->writeInt(mD3DUniforms.size());
Jamie Madill4a3c2342015-10-08 12:58:45 -0400993 for (const D3DUniform *uniform : mD3DUniforms)
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700994 {
Jamie Madill62d31cb2015-09-11 13:25:51 -0400995 // Type, name and arraySize are redundant, so aren't stored in the binary.
Jamie Madille2e406c2016-06-02 13:04:10 -0400996 stream->writeIntOrNegOne(uniform->psRegisterIndex);
997 stream->writeIntOrNegOne(uniform->vsRegisterIndex);
Jamie Madill4a3c2342015-10-08 12:58:45 -0400998 stream->writeInt(uniform->registerCount);
999 stream->writeInt(uniform->registerElement);
1000 }
1001
1002 stream->writeInt(mD3DUniformBlocks.size());
1003 for (const D3DUniformBlock &uniformBlock : mD3DUniformBlocks)
1004 {
Jamie Madille2e406c2016-06-02 13:04:10 -04001005 stream->writeIntOrNegOne(uniformBlock.psRegisterIndex);
1006 stream->writeIntOrNegOne(uniformBlock.vsRegisterIndex);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001007 }
1008
Jamie Madill9fc36822015-11-18 13:08:07 -05001009 stream->writeInt(mStreamOutVaryings.size());
1010 for (const auto &varying : mStreamOutVaryings)
Brandon Joneseb994362014-09-24 10:27:28 -07001011 {
Brandon Joneseb994362014-09-24 10:27:28 -07001012 stream->writeString(varying.semanticName);
1013 stream->writeInt(varying.semanticIndex);
Jamie Madill9fc36822015-11-18 13:08:07 -05001014 stream->writeInt(varying.componentCount);
1015 stream->writeInt(varying.outputSlot);
Brandon Joneseb994362014-09-24 10:27:28 -07001016 }
1017
Brandon Jones22502d52014-08-29 16:58:36 -07001018 stream->writeString(mVertexHLSL);
Jamie Madill334d6152015-10-22 14:00:28 -04001019 stream->writeBytes(reinterpret_cast<unsigned char *>(&mVertexWorkarounds),
1020 sizeof(D3DCompilerWorkarounds));
Brandon Jones22502d52014-08-29 16:58:36 -07001021 stream->writeString(mPixelHLSL);
Jamie Madill334d6152015-10-22 14:00:28 -04001022 stream->writeBytes(reinterpret_cast<unsigned char *>(&mPixelWorkarounds),
1023 sizeof(D3DCompilerWorkarounds));
Brandon Jones22502d52014-08-29 16:58:36 -07001024 stream->writeInt(mUsesFragDepth);
Brandon Jones44151a92014-09-10 11:32:25 -07001025 stream->writeInt(mUsesPointSize);
Jamie Madill3e14e2b2015-10-29 14:38:53 -04001026 stream->writeInt(mUsesFlatInterpolation);
Brandon Jones22502d52014-08-29 16:58:36 -07001027
Brandon Joneseb994362014-09-24 10:27:28 -07001028 const std::vector<PixelShaderOutputVariable> &pixelShaderKey = mPixelShaderKey;
Brandon Jones22502d52014-08-29 16:58:36 -07001029 stream->writeInt(pixelShaderKey.size());
Jamie Madill334d6152015-10-22 14:00:28 -04001030 for (size_t pixelShaderKeyIndex = 0; pixelShaderKeyIndex < pixelShaderKey.size();
1031 pixelShaderKeyIndex++)
Brandon Jones22502d52014-08-29 16:58:36 -07001032 {
Brandon Joneseb994362014-09-24 10:27:28 -07001033 const PixelShaderOutputVariable &variable = pixelShaderKey[pixelShaderKeyIndex];
Brandon Jones22502d52014-08-29 16:58:36 -07001034 stream->writeInt(variable.type);
1035 stream->writeString(variable.name);
1036 stream->writeString(variable.source);
1037 stream->writeInt(variable.outputIndex);
1038 }
1039
Jamie Madill4e31ad52015-10-29 10:32:57 -04001040 stream->writeString(mGeometryShaderPreamble);
1041
Brandon Joneseb994362014-09-24 10:27:28 -07001042 stream->writeInt(mVertexExecutables.size());
Jamie Madill334d6152015-10-22 14:00:28 -04001043 for (size_t vertexExecutableIndex = 0; vertexExecutableIndex < mVertexExecutables.size();
1044 vertexExecutableIndex++)
Brandon Joneseb994362014-09-24 10:27:28 -07001045 {
1046 VertexExecutable *vertexExecutable = mVertexExecutables[vertexExecutableIndex];
1047
Jamie Madilld3dfda22015-07-06 08:28:49 -04001048 const auto &inputLayout = vertexExecutable->inputs();
1049 stream->writeInt(inputLayout.size());
1050
1051 for (size_t inputIndex = 0; inputIndex < inputLayout.size(); inputIndex++)
Brandon Joneseb994362014-09-24 10:27:28 -07001052 {
Jamie Madille2e406c2016-06-02 13:04:10 -04001053 stream->writeInt(static_cast<unsigned int>(inputLayout[inputIndex]));
Brandon Joneseb994362014-09-24 10:27:28 -07001054 }
1055
1056 size_t vertexShaderSize = vertexExecutable->shaderExecutable()->getLength();
1057 stream->writeInt(vertexShaderSize);
1058
1059 const uint8_t *vertexBlob = vertexExecutable->shaderExecutable()->getFunction();
1060 stream->writeBytes(vertexBlob, vertexShaderSize);
1061 }
1062
1063 stream->writeInt(mPixelExecutables.size());
Jamie Madill334d6152015-10-22 14:00:28 -04001064 for (size_t pixelExecutableIndex = 0; pixelExecutableIndex < mPixelExecutables.size();
1065 pixelExecutableIndex++)
Brandon Joneseb994362014-09-24 10:27:28 -07001066 {
1067 PixelExecutable *pixelExecutable = mPixelExecutables[pixelExecutableIndex];
1068
1069 const std::vector<GLenum> outputs = pixelExecutable->outputSignature();
1070 stream->writeInt(outputs.size());
1071 for (size_t outputIndex = 0; outputIndex < outputs.size(); outputIndex++)
1072 {
1073 stream->writeInt(outputs[outputIndex]);
1074 }
1075
1076 size_t pixelShaderSize = pixelExecutable->shaderExecutable()->getLength();
1077 stream->writeInt(pixelShaderSize);
1078
1079 const uint8_t *pixelBlob = pixelExecutable->shaderExecutable()->getFunction();
1080 stream->writeBytes(pixelBlob, pixelShaderSize);
1081 }
1082
Jamie Madill4e31ad52015-10-29 10:32:57 -04001083 for (const ShaderExecutableD3D *geometryExe : mGeometryExecutables)
Brandon Joneseb994362014-09-24 10:27:28 -07001084 {
Jamie Madill4e31ad52015-10-29 10:32:57 -04001085 if (geometryExe == nullptr)
1086 {
1087 stream->writeInt(0);
1088 continue;
1089 }
1090
1091 size_t geometryShaderSize = geometryExe->getLength();
1092 stream->writeInt(geometryShaderSize);
1093 stream->writeBytes(geometryExe->getFunction(), geometryShaderSize);
Brandon Joneseb994362014-09-24 10:27:28 -07001094 }
1095
Geoff Langb543aff2014-09-30 14:52:54 -04001096 return gl::Error(GL_NO_ERROR);
Brandon Jones22502d52014-08-29 16:58:36 -07001097}
1098
Geoff Langc5629752015-12-07 16:29:04 -05001099void ProgramD3D::setBinaryRetrievableHint(bool /* retrievable */)
1100{
1101}
1102
Jamie Madill334d6152015-10-22 14:00:28 -04001103gl::Error ProgramD3D::getPixelExecutableForFramebuffer(const gl::Framebuffer *fbo,
1104 ShaderExecutableD3D **outExecutable)
Brandon Jones22502d52014-08-29 16:58:36 -07001105{
Geoff Lang7a26a1a2015-03-25 12:29:06 -04001106 mPixelShaderOutputFormatCache.clear();
Brandon Joneseb994362014-09-24 10:27:28 -07001107
Jamie Madill85a18042015-03-05 15:41:41 -05001108 const FramebufferD3D *fboD3D = GetImplAs<FramebufferD3D>(fbo);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05001109 const gl::AttachmentList &colorbuffers = fboD3D->getColorAttachmentsForRender();
Brandon Joneseb994362014-09-24 10:27:28 -07001110
1111 for (size_t colorAttachment = 0; colorAttachment < colorbuffers.size(); ++colorAttachment)
1112 {
1113 const gl::FramebufferAttachment *colorbuffer = colorbuffers[colorAttachment];
1114
1115 if (colorbuffer)
1116 {
Jamie Madill334d6152015-10-22 14:00:28 -04001117 mPixelShaderOutputFormatCache.push_back(colorbuffer->getBinding() == GL_BACK
1118 ? GL_COLOR_ATTACHMENT0
1119 : colorbuffer->getBinding());
Brandon Joneseb994362014-09-24 10:27:28 -07001120 }
1121 else
1122 {
Geoff Lang7a26a1a2015-03-25 12:29:06 -04001123 mPixelShaderOutputFormatCache.push_back(GL_NONE);
Brandon Joneseb994362014-09-24 10:27:28 -07001124 }
1125 }
1126
Geoff Lang7a26a1a2015-03-25 12:29:06 -04001127 return getPixelExecutableForOutputLayout(mPixelShaderOutputFormatCache, outExecutable, nullptr);
Brandon Joneseb994362014-09-24 10:27:28 -07001128}
1129
Jamie Madill97399232014-12-23 12:31:15 -05001130gl::Error ProgramD3D::getPixelExecutableForOutputLayout(const std::vector<GLenum> &outputSignature,
Geoff Lang359ef262015-01-05 14:42:29 -05001131 ShaderExecutableD3D **outExectuable,
Jamie Madill97399232014-12-23 12:31:15 -05001132 gl::InfoLog *infoLog)
Brandon Joneseb994362014-09-24 10:27:28 -07001133{
1134 for (size_t executableIndex = 0; executableIndex < mPixelExecutables.size(); executableIndex++)
1135 {
1136 if (mPixelExecutables[executableIndex]->matchesSignature(outputSignature))
1137 {
Geoff Langb543aff2014-09-30 14:52:54 -04001138 *outExectuable = mPixelExecutables[executableIndex]->shaderExecutable();
1139 return gl::Error(GL_NO_ERROR);
Brandon Joneseb994362014-09-24 10:27:28 -07001140 }
1141 }
1142
Jamie Madill334d6152015-10-22 14:00:28 -04001143 std::string finalPixelHLSL = mDynamicHLSL->generatePixelShaderForOutputSignature(
1144 mPixelHLSL, mPixelShaderKey, mUsesFragDepth, outputSignature);
Brandon Jones22502d52014-08-29 16:58:36 -07001145
1146 // Generate new pixel executable
Geoff Lang359ef262015-01-05 14:42:29 -05001147 ShaderExecutableD3D *pixelExecutable = NULL;
Jamie Madill97399232014-12-23 12:31:15 -05001148
1149 gl::InfoLog tempInfoLog;
1150 gl::InfoLog *currentInfoLog = infoLog ? infoLog : &tempInfoLog;
1151
Jamie Madill01074252016-11-28 15:55:51 -05001152 ANGLE_TRY(mRenderer->compileToExecutable(
Jamie Madill9fc36822015-11-18 13:08:07 -05001153 *currentInfoLog, finalPixelHLSL, SHADER_PIXEL, mStreamOutVaryings,
Jamie Madill48ef11b2016-04-27 15:21:52 -04001154 (mState.getTransformFeedbackBufferMode() == GL_SEPARATE_ATTRIBS), mPixelWorkarounds,
Jamie Madill01074252016-11-28 15:55:51 -05001155 &pixelExecutable));
Brandon Joneseb994362014-09-24 10:27:28 -07001156
Jamie Madill97399232014-12-23 12:31:15 -05001157 if (pixelExecutable)
1158 {
1159 mPixelExecutables.push_back(new PixelExecutable(outputSignature, pixelExecutable));
1160 }
1161 else if (!infoLog)
Brandon Joneseb994362014-09-24 10:27:28 -07001162 {
1163 std::vector<char> tempCharBuffer(tempInfoLog.getLength() + 3);
Cooper Partin4d61f7e2015-08-12 10:56:50 -07001164 tempInfoLog.getLog(static_cast<GLsizei>(tempInfoLog.getLength()), NULL, &tempCharBuffer[0]);
Brandon Joneseb994362014-09-24 10:27:28 -07001165 ERR("Error compiling dynamic pixel executable:\n%s\n", &tempCharBuffer[0]);
1166 }
Brandon Jones22502d52014-08-29 16:58:36 -07001167
Geoff Langb543aff2014-09-30 14:52:54 -04001168 *outExectuable = pixelExecutable;
Jamie Madill01074252016-11-28 15:55:51 -05001169 return gl::NoError();
Brandon Jones22502d52014-08-29 16:58:36 -07001170}
1171
Jamie Madilld3dfda22015-07-06 08:28:49 -04001172gl::Error ProgramD3D::getVertexExecutableForInputLayout(const gl::InputLayout &inputLayout,
Geoff Lang359ef262015-01-05 14:42:29 -05001173 ShaderExecutableD3D **outExectuable,
Jamie Madill97399232014-12-23 12:31:15 -05001174 gl::InfoLog *infoLog)
Brandon Jones22502d52014-08-29 16:58:36 -07001175{
Jamie Madilld3dfda22015-07-06 08:28:49 -04001176 VertexExecutable::getSignature(mRenderer, inputLayout, &mCachedVertexSignature);
Brandon Joneseb994362014-09-24 10:27:28 -07001177
1178 for (size_t executableIndex = 0; executableIndex < mVertexExecutables.size(); executableIndex++)
1179 {
Jamie Madilld3dfda22015-07-06 08:28:49 -04001180 if (mVertexExecutables[executableIndex]->matchesSignature(mCachedVertexSignature))
Brandon Joneseb994362014-09-24 10:27:28 -07001181 {
Geoff Langb543aff2014-09-30 14:52:54 -04001182 *outExectuable = mVertexExecutables[executableIndex]->shaderExecutable();
1183 return gl::Error(GL_NO_ERROR);
Brandon Joneseb994362014-09-24 10:27:28 -07001184 }
1185 }
1186
Brandon Jones22502d52014-08-29 16:58:36 -07001187 // Generate new dynamic layout with attribute conversions
Jamie Madillc349ec02015-08-21 16:53:12 -04001188 std::string finalVertexHLSL = mDynamicHLSL->generateVertexShaderForInputLayout(
Jamie Madill48ef11b2016-04-27 15:21:52 -04001189 mVertexHLSL, inputLayout, mState.getAttributes());
Brandon Jones22502d52014-08-29 16:58:36 -07001190
1191 // Generate new vertex executable
Geoff Lang359ef262015-01-05 14:42:29 -05001192 ShaderExecutableD3D *vertexExecutable = NULL;
Jamie Madill97399232014-12-23 12:31:15 -05001193
1194 gl::InfoLog tempInfoLog;
1195 gl::InfoLog *currentInfoLog = infoLog ? infoLog : &tempInfoLog;
1196
Jamie Madill01074252016-11-28 15:55:51 -05001197 ANGLE_TRY(mRenderer->compileToExecutable(
Jamie Madill9fc36822015-11-18 13:08:07 -05001198 *currentInfoLog, finalVertexHLSL, SHADER_VERTEX, mStreamOutVaryings,
Jamie Madill48ef11b2016-04-27 15:21:52 -04001199 (mState.getTransformFeedbackBufferMode() == GL_SEPARATE_ATTRIBS), mVertexWorkarounds,
Jamie Madill01074252016-11-28 15:55:51 -05001200 &vertexExecutable));
Geoff Langb543aff2014-09-30 14:52:54 -04001201
Jamie Madill97399232014-12-23 12:31:15 -05001202 if (vertexExecutable)
Brandon Joneseb994362014-09-24 10:27:28 -07001203 {
Jamie Madill334d6152015-10-22 14:00:28 -04001204 mVertexExecutables.push_back(
1205 new VertexExecutable(inputLayout, mCachedVertexSignature, vertexExecutable));
Brandon Joneseb994362014-09-24 10:27:28 -07001206 }
Jamie Madill97399232014-12-23 12:31:15 -05001207 else if (!infoLog)
1208 {
1209 std::vector<char> tempCharBuffer(tempInfoLog.getLength() + 3);
Cooper Partin4d61f7e2015-08-12 10:56:50 -07001210 tempInfoLog.getLog(static_cast<GLsizei>(tempInfoLog.getLength()), NULL, &tempCharBuffer[0]);
Jamie Madill97399232014-12-23 12:31:15 -05001211 ERR("Error compiling dynamic vertex executable:\n%s\n", &tempCharBuffer[0]);
1212 }
Brandon Jones22502d52014-08-29 16:58:36 -07001213
Geoff Langb543aff2014-09-30 14:52:54 -04001214 *outExectuable = vertexExecutable;
Jamie Madill01074252016-11-28 15:55:51 -05001215 return gl::NoError();
Brandon Jones22502d52014-08-29 16:58:36 -07001216}
1217
Jamie Madill9082b982016-04-27 15:21:51 -04001218gl::Error ProgramD3D::getGeometryExecutableForPrimitiveType(const gl::ContextState &data,
Jamie Madill4e31ad52015-10-29 10:32:57 -04001219 GLenum drawMode,
1220 ShaderExecutableD3D **outExecutable,
1221 gl::InfoLog *infoLog)
1222{
Jamie Madill3e14e2b2015-10-29 14:38:53 -04001223 if (outExecutable)
1224 {
1225 *outExecutable = nullptr;
1226 }
1227
Austin Kinross88829e82016-01-12 13:04:41 -08001228 // Return a null shader if the current rendering doesn't use a geometry shader
1229 if (!usesGeometryShader(drawMode))
Jamie Madill3e14e2b2015-10-29 14:38:53 -04001230 {
1231 return gl::Error(GL_NO_ERROR);
1232 }
1233
Jamie Madill4e31ad52015-10-29 10:32:57 -04001234 gl::PrimitiveType geometryShaderType = GetGeometryShaderTypeFromDrawMode(drawMode);
1235
1236 if (mGeometryExecutables[geometryShaderType] != nullptr)
1237 {
1238 if (outExecutable)
1239 {
1240 *outExecutable = mGeometryExecutables[geometryShaderType];
1241 }
1242 return gl::Error(GL_NO_ERROR);
1243 }
1244
1245 std::string geometryHLSL = mDynamicHLSL->generateGeometryShaderHLSL(
Jamie Madill48ef11b2016-04-27 15:21:52 -04001246 geometryShaderType, data, mState, mRenderer->presentPathFastEnabled(),
Austin Kinross2a63b3f2016-02-08 12:29:08 -08001247 mGeometryShaderPreamble);
Jamie Madill4e31ad52015-10-29 10:32:57 -04001248
1249 gl::InfoLog tempInfoLog;
1250 gl::InfoLog *currentInfoLog = infoLog ? infoLog : &tempInfoLog;
1251
1252 gl::Error error = mRenderer->compileToExecutable(
Jamie Madill9fc36822015-11-18 13:08:07 -05001253 *currentInfoLog, geometryHLSL, SHADER_GEOMETRY, mStreamOutVaryings,
Jamie Madill48ef11b2016-04-27 15:21:52 -04001254 (mState.getTransformFeedbackBufferMode() == GL_SEPARATE_ATTRIBS), D3DCompilerWorkarounds(),
Jamie Madill4e31ad52015-10-29 10:32:57 -04001255 &mGeometryExecutables[geometryShaderType]);
1256
1257 if (!infoLog && error.isError())
1258 {
1259 std::vector<char> tempCharBuffer(tempInfoLog.getLength() + 3);
1260 tempInfoLog.getLog(static_cast<GLsizei>(tempInfoLog.getLength()), NULL, &tempCharBuffer[0]);
1261 ERR("Error compiling dynamic geometry executable:\n%s\n", &tempCharBuffer[0]);
1262 }
1263
1264 if (outExecutable)
1265 {
1266 *outExecutable = mGeometryExecutables[geometryShaderType];
1267 }
1268 return error;
1269}
1270
Jamie Madill01074252016-11-28 15:55:51 -05001271class ProgramD3D::GetExecutableTask : public Closure
Brandon Jones44151a92014-09-10 11:32:25 -07001272{
Jamie Madill01074252016-11-28 15:55:51 -05001273 public:
1274 GetExecutableTask(ProgramD3D *program)
1275 : mProgram(program), mError(GL_NO_ERROR), mInfoLog(), mResult(nullptr)
Brandon Joneseb994362014-09-24 10:27:28 -07001276 {
Brandon Joneseb994362014-09-24 10:27:28 -07001277 }
1278
Jamie Madill01074252016-11-28 15:55:51 -05001279 virtual gl::Error run() = 0;
1280
1281 void operator()() override { mError = run(); }
1282
1283 const gl::Error &getError() const { return mError; }
1284 const gl::InfoLog &getInfoLog() const { return mInfoLog; }
1285 ShaderExecutableD3D *getResult() { return mResult; }
1286
1287 protected:
1288 ProgramD3D *mProgram;
1289 gl::Error mError;
1290 gl::InfoLog mInfoLog;
1291 ShaderExecutableD3D *mResult;
1292};
1293
1294class ProgramD3D::GetVertexExecutableTask : public ProgramD3D::GetExecutableTask
1295{
1296 public:
1297 GetVertexExecutableTask(ProgramD3D *program) : GetExecutableTask(program) {}
1298 gl::Error run() override
1299 {
1300 const auto &defaultInputLayout =
1301 GetDefaultInputLayoutFromShader(mProgram->mState.getAttachedVertexShader());
1302
1303 ANGLE_TRY(
1304 mProgram->getVertexExecutableForInputLayout(defaultInputLayout, &mResult, &mInfoLog));
1305
1306 return gl::NoError();
1307 }
1308};
1309
1310class ProgramD3D::GetPixelExecutableTask : public ProgramD3D::GetExecutableTask
1311{
1312 public:
1313 GetPixelExecutableTask(ProgramD3D *program) : GetExecutableTask(program) {}
1314 gl::Error run() override
1315 {
1316 const auto &defaultPixelOutput =
1317 GetDefaultOutputLayoutFromShader(mProgram->getPixelShaderKey());
1318
1319 ANGLE_TRY(
1320 mProgram->getPixelExecutableForOutputLayout(defaultPixelOutput, &mResult, &mInfoLog));
1321
1322 return gl::NoError();
1323 }
1324};
1325
1326class ProgramD3D::GetGeometryExecutableTask : public ProgramD3D::GetExecutableTask
1327{
1328 public:
1329 GetGeometryExecutableTask(ProgramD3D *program, const gl::ContextState &contextState)
1330 : GetExecutableTask(program), mContextState(contextState)
1331 {
1332 }
1333
1334 gl::Error run() override
1335 {
1336 // Auto-generate the geometry shader here, if we expect to be using point rendering in
1337 // D3D11.
1338 if (mProgram->usesGeometryShader(GL_POINTS))
1339 {
1340 ANGLE_TRY(mProgram->getGeometryExecutableForPrimitiveType(mContextState, GL_POINTS,
1341 &mResult, &mInfoLog));
1342 }
1343
1344 return gl::NoError();
1345 }
1346
1347 private:
1348 const gl::ContextState &mContextState;
1349};
1350
1351LinkResult ProgramD3D::compileProgramExecutables(const gl::ContextState &contextState,
1352 gl::InfoLog &infoLog)
1353{
1354 // Ensure the compiler is initialized to avoid race conditions.
1355 ANGLE_TRY(mRenderer->ensureHLSLCompilerInitialized());
1356
1357 WorkerThreadPool *workerPool = mRenderer->getWorkerThreadPool();
1358
1359 GetVertexExecutableTask vertexTask(this);
1360 GetPixelExecutableTask pixelTask(this);
1361 GetGeometryExecutableTask geometryTask(this, contextState);
1362
1363 std::array<WaitableEvent, 3> waitEvents = {{workerPool->postWorkerTask(&vertexTask),
1364 workerPool->postWorkerTask(&pixelTask),
1365 workerPool->postWorkerTask(&geometryTask)}};
1366
1367 WaitableEvent::WaitMany(&waitEvents);
1368
1369 infoLog << vertexTask.getInfoLog().str();
1370 infoLog << pixelTask.getInfoLog().str();
1371 infoLog << geometryTask.getInfoLog().str();
1372
1373 ANGLE_TRY(vertexTask.getError());
1374 ANGLE_TRY(pixelTask.getError());
1375 ANGLE_TRY(geometryTask.getError());
1376
1377 ShaderExecutableD3D *defaultVertexExecutable = vertexTask.getResult();
1378 ShaderExecutableD3D *defaultPixelExecutable = pixelTask.getResult();
1379 ShaderExecutableD3D *pointGS = geometryTask.getResult();
1380
Jamie Madill48ef11b2016-04-27 15:21:52 -04001381 const ShaderD3D *vertexShaderD3D = GetImplAs<ShaderD3D>(mState.getAttachedVertexShader());
Jamie Madill847638a2015-11-20 13:01:41 -05001382
1383 if (usesGeometryShader(GL_POINTS) && pointGS)
Tibor den Ouden97049c62014-10-06 21:39:16 +02001384 {
Jamie Madill334d6152015-10-22 14:00:28 -04001385 // Geometry shaders are currently only used internally, so there is no corresponding shader
1386 // object at the interface level. For now the geometry shader debug info is prepended to
1387 // the vertex shader.
Tibor den Ouden97049c62014-10-06 21:39:16 +02001388 vertexShaderD3D->appendDebugInfo("// GEOMETRY SHADER BEGIN\n\n");
Jamie Madill847638a2015-11-20 13:01:41 -05001389 vertexShaderD3D->appendDebugInfo(pointGS->getDebugInfo());
Tibor den Ouden97049c62014-10-06 21:39:16 +02001390 vertexShaderD3D->appendDebugInfo("\nGEOMETRY SHADER END\n\n\n");
1391 }
1392
1393 if (defaultVertexExecutable)
1394 {
1395 vertexShaderD3D->appendDebugInfo(defaultVertexExecutable->getDebugInfo());
1396 }
1397
1398 if (defaultPixelExecutable)
1399 {
Jamie Madill76f8fa62015-10-29 10:32:56 -04001400 const ShaderD3D *fragmentShaderD3D =
Jamie Madill48ef11b2016-04-27 15:21:52 -04001401 GetImplAs<ShaderD3D>(mState.getAttachedFragmentShader());
Tibor den Ouden97049c62014-10-06 21:39:16 +02001402 fragmentShaderD3D->appendDebugInfo(defaultPixelExecutable->getDebugInfo());
1403 }
Tibor den Ouden97049c62014-10-06 21:39:16 +02001404
Jamie Madillb0a838b2016-11-13 20:02:12 -05001405 return (defaultVertexExecutable && defaultPixelExecutable &&
1406 (!usesGeometryShader(GL_POINTS) || pointGS));
Brandon Jones18bd4102014-09-22 14:21:44 -07001407}
1408
Jamie Madill9082b982016-04-27 15:21:51 -04001409LinkResult ProgramD3D::link(const gl::ContextState &data, gl::InfoLog &infoLog)
Brandon Jones22502d52014-08-29 16:58:36 -07001410{
Jamie Madill62d31cb2015-09-11 13:25:51 -04001411 reset();
1412
Jamie Madill48ef11b2016-04-27 15:21:52 -04001413 const gl::Shader *vertexShader = mState.getAttachedVertexShader();
1414 const gl::Shader *fragmentShader = mState.getAttachedFragmentShader();
Brandon Joneseb994362014-09-24 10:27:28 -07001415
Jamie Madillf5f4ad22015-09-02 18:32:38 +00001416 const ShaderD3D *vertexShaderD3D = GetImplAs<ShaderD3D>(vertexShader);
1417 const ShaderD3D *fragmentShaderD3D = GetImplAs<ShaderD3D>(fragmentShader);
1418
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001419 mSamplersVS.resize(data.getCaps().maxVertexTextureImageUnits);
1420 mSamplersPS.resize(data.getCaps().maxTextureImageUnits);
Brandon Jones22502d52014-08-29 16:58:36 -07001421
Arun Patole44efa0b2015-03-04 17:11:05 +05301422 vertexShaderD3D->generateWorkarounds(&mVertexWorkarounds);
Jamie Madillf5f4ad22015-09-02 18:32:38 +00001423 fragmentShaderD3D->generateWorkarounds(&mPixelWorkarounds);
1424
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001425 if (mRenderer->getNativeLimitations().noFrontFacingSupport)
Austin Kinross02df7962015-07-01 10:03:42 -07001426 {
1427 if (fragmentShaderD3D->usesFrontFacing())
1428 {
1429 infoLog << "The current renderer doesn't support gl_FrontFacing";
Jamie Madillb0a838b2016-11-13 20:02:12 -05001430 return false;
Austin Kinross02df7962015-07-01 10:03:42 -07001431 }
1432 }
1433
Jamie Madillca03b352015-09-02 12:38:13 -04001434 std::vector<PackedVarying> packedVaryings =
Jamie Madill48ef11b2016-04-27 15:21:52 -04001435 MergeVaryings(*vertexShader, *fragmentShader, mState.getTransformFeedbackVaryingNames());
Jamie Madillca03b352015-09-02 12:38:13 -04001436
Brandon Jones22502d52014-08-29 16:58:36 -07001437 // Map the varyings to the register file
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001438 VaryingPacking varyingPacking(data.getCaps().maxVaryingVectors);
Jamie Madill9fc36822015-11-18 13:08:07 -05001439 if (!varyingPacking.packVaryings(infoLog, packedVaryings,
Jamie Madill48ef11b2016-04-27 15:21:52 -04001440 mState.getTransformFeedbackVaryingNames()))
Brandon Jones22502d52014-08-29 16:58:36 -07001441 {
Jamie Madillb0a838b2016-11-13 20:02:12 -05001442 return false;
Brandon Jones22502d52014-08-29 16:58:36 -07001443 }
1444
Jamie Madillc9bde922016-07-24 17:58:50 -04001445 ProgramD3DMetadata metadata(mRenderer, vertexShaderD3D, fragmentShaderD3D);
Jamie Madille39a3f02015-11-17 20:42:15 -05001446
Jamie Madill9fc36822015-11-18 13:08:07 -05001447 varyingPacking.enableBuiltins(SHADER_VERTEX, metadata);
1448 varyingPacking.enableBuiltins(SHADER_PIXEL, metadata);
1449
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001450 if (static_cast<GLuint>(varyingPacking.getRegisterCount()) > data.getCaps().maxVaryingVectors)
Jamie Madill9fc36822015-11-18 13:08:07 -05001451 {
1452 infoLog << "No varying registers left to support gl_FragCoord/gl_PointCoord";
Jamie Madillb0a838b2016-11-13 20:02:12 -05001453 return false;
Jamie Madill9fc36822015-11-18 13:08:07 -05001454 }
1455
1456 // TODO(jmadill): Implement more sophisticated component packing in D3D9.
1457 // We can fail here because we use one semantic per GLSL varying. D3D11 can pack varyings
1458 // intelligently, but D3D9 assumes one semantic per register.
1459 if (mRenderer->getRendererClass() == RENDERER_D3D9 &&
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001460 varyingPacking.getMaxSemanticIndex() > data.getCaps().maxVaryingVectors)
Jamie Madill9fc36822015-11-18 13:08:07 -05001461 {
1462 infoLog << "Cannot pack these varyings on D3D9.";
Jamie Madillb0a838b2016-11-13 20:02:12 -05001463 return false;
Jamie Madill9fc36822015-11-18 13:08:07 -05001464 }
1465
Jamie Madill48ef11b2016-04-27 15:21:52 -04001466 if (!mDynamicHLSL->generateShaderLinkHLSL(data, mState, metadata, varyingPacking, &mPixelHLSL,
Jamie Madill9fc36822015-11-18 13:08:07 -05001467 &mVertexHLSL))
Brandon Jones22502d52014-08-29 16:58:36 -07001468 {
Jamie Madillb0a838b2016-11-13 20:02:12 -05001469 return false;
Brandon Jones22502d52014-08-29 16:58:36 -07001470 }
1471
Brandon Jones44151a92014-09-10 11:32:25 -07001472 mUsesPointSize = vertexShaderD3D->usesPointSize();
Jamie Madill48ef11b2016-04-27 15:21:52 -04001473 mDynamicHLSL->getPixelShaderOutputKey(data, mState, metadata, &mPixelShaderKey);
1474 mUsesFragDepth = metadata.usesFragDepth();
Brandon Jones44151a92014-09-10 11:32:25 -07001475
Jamie Madill3e14e2b2015-10-29 14:38:53 -04001476 // Cache if we use flat shading
Jamie Madill55c25d02015-11-18 13:08:08 -05001477 mUsesFlatInterpolation = false;
Jamie Madill3e14e2b2015-10-29 14:38:53 -04001478 for (const auto &varying : packedVaryings)
1479 {
Jamie Madill55c25d02015-11-18 13:08:08 -05001480 if (varying.interpolation == sh::INTERPOLATION_FLAT)
Jamie Madill3e14e2b2015-10-29 14:38:53 -04001481 {
1482 mUsesFlatInterpolation = true;
1483 break;
1484 }
1485 }
1486
Jamie Madill4e31ad52015-10-29 10:32:57 -04001487 if (mRenderer->getMajorShaderModel() >= 4)
1488 {
Jamie Madill9fc36822015-11-18 13:08:07 -05001489 varyingPacking.enableBuiltins(SHADER_GEOMETRY, metadata);
1490 mGeometryShaderPreamble = mDynamicHLSL->generateGeometryShaderPreamble(varyingPacking);
Jamie Madill4e31ad52015-10-29 10:32:57 -04001491 }
1492
Jamie Madill8047c0d2016-03-07 13:02:12 -05001493 initAttribLocationsToD3DSemantic();
Jamie Madill437d2662014-12-05 14:23:35 -05001494
Jamie Madill3d3d2f22015-09-23 16:47:51 -04001495 defineUniformsAndAssignRegisters();
Jamie Madille473dee2015-08-18 14:49:01 -04001496
Jamie Madill9fc36822015-11-18 13:08:07 -05001497 gatherTransformFeedbackVaryings(varyingPacking);
Jamie Madillccdf74b2015-08-18 10:46:12 -04001498
Jamie Madill4e31ad52015-10-29 10:32:57 -04001499 LinkResult result = compileProgramExecutables(data, infoLog);
Jamie Madillb0a838b2016-11-13 20:02:12 -05001500 if (result.isError())
Geoff Lang65d17e52016-09-08 09:52:58 -04001501 {
Jamie Madillb0a838b2016-11-13 20:02:12 -05001502 infoLog << result.getError().getMessage();
Geoff Lang65d17e52016-09-08 09:52:58 -04001503 return result;
1504 }
Jamie Madillb0a838b2016-11-13 20:02:12 -05001505 else if (!result.getResult())
Jamie Madill31c8c562015-08-19 14:08:03 -04001506 {
1507 infoLog << "Failed to create D3D shaders.";
1508 return result;
1509 }
1510
Jamie Madill4a3c2342015-10-08 12:58:45 -04001511 initUniformBlockInfo();
1512
Jamie Madillb0a838b2016-11-13 20:02:12 -05001513 return true;
Brandon Jones22502d52014-08-29 16:58:36 -07001514}
1515
Jamie Madill3d3d2f22015-09-23 16:47:51 -04001516GLboolean ProgramD3D::validate(const gl::Caps & /*caps*/, gl::InfoLog * /*infoLog*/)
Jamie Madill36cfd6a2015-08-18 10:46:20 -04001517{
Jamie Madill3d3d2f22015-09-23 16:47:51 -04001518 // TODO(jmadill): Do something useful here?
1519 return GL_TRUE;
Jamie Madill36cfd6a2015-08-18 10:46:20 -04001520}
1521
Jamie Madill4a3c2342015-10-08 12:58:45 -04001522void ProgramD3D::initUniformBlockInfo()
Jamie Madill62d31cb2015-09-11 13:25:51 -04001523{
Jamie Madill48ef11b2016-04-27 15:21:52 -04001524 const gl::Shader *vertexShader = mState.getAttachedVertexShader();
Jamie Madill62d31cb2015-09-11 13:25:51 -04001525
Jamie Madill62d31cb2015-09-11 13:25:51 -04001526 for (const sh::InterfaceBlock &vertexBlock : vertexShader->getInterfaceBlocks())
1527 {
1528 if (!vertexBlock.staticUse && vertexBlock.layout == sh::BLOCKLAYOUT_PACKED)
1529 continue;
1530
Jamie Madill4a3c2342015-10-08 12:58:45 -04001531 if (mBlockDataSizes.count(vertexBlock.name) > 0)
Jamie Madill62d31cb2015-09-11 13:25:51 -04001532 continue;
1533
Jamie Madill4a3c2342015-10-08 12:58:45 -04001534 size_t dataSize = getUniformBlockInfo(vertexBlock);
1535 mBlockDataSizes[vertexBlock.name] = dataSize;
Jamie Madill62d31cb2015-09-11 13:25:51 -04001536 }
1537
Jamie Madill48ef11b2016-04-27 15:21:52 -04001538 const gl::Shader *fragmentShader = mState.getAttachedFragmentShader();
Jamie Madill62d31cb2015-09-11 13:25:51 -04001539
1540 for (const sh::InterfaceBlock &fragmentBlock : fragmentShader->getInterfaceBlocks())
1541 {
1542 if (!fragmentBlock.staticUse && fragmentBlock.layout == sh::BLOCKLAYOUT_PACKED)
1543 continue;
1544
Jamie Madill4a3c2342015-10-08 12:58:45 -04001545 if (mBlockDataSizes.count(fragmentBlock.name) > 0)
Jamie Madill62d31cb2015-09-11 13:25:51 -04001546 continue;
1547
Jamie Madill4a3c2342015-10-08 12:58:45 -04001548 size_t dataSize = getUniformBlockInfo(fragmentBlock);
1549 mBlockDataSizes[fragmentBlock.name] = dataSize;
Jamie Madill62d31cb2015-09-11 13:25:51 -04001550 }
Jamie Madill4a3c2342015-10-08 12:58:45 -04001551}
Jamie Madill62d31cb2015-09-11 13:25:51 -04001552
Jamie Madill4a3c2342015-10-08 12:58:45 -04001553void ProgramD3D::assignUniformBlockRegisters()
1554{
1555 mD3DUniformBlocks.clear();
Jamie Madill62d31cb2015-09-11 13:25:51 -04001556
1557 // Assign registers and update sizes.
Jamie Madill48ef11b2016-04-27 15:21:52 -04001558 const ShaderD3D *vertexShaderD3D = GetImplAs<ShaderD3D>(mState.getAttachedVertexShader());
1559 const ShaderD3D *fragmentShaderD3D = GetImplAs<ShaderD3D>(mState.getAttachedFragmentShader());
Jamie Madill62d31cb2015-09-11 13:25:51 -04001560
Jamie Madill48ef11b2016-04-27 15:21:52 -04001561 for (const gl::UniformBlock &uniformBlock : mState.getUniformBlocks())
Jamie Madill62d31cb2015-09-11 13:25:51 -04001562 {
1563 unsigned int uniformBlockElement = uniformBlock.isArray ? uniformBlock.arrayElement : 0;
1564
Jamie Madill4a3c2342015-10-08 12:58:45 -04001565 D3DUniformBlock d3dUniformBlock;
1566
Jamie Madill62d31cb2015-09-11 13:25:51 -04001567 if (uniformBlock.vertexStaticUse)
1568 {
1569 unsigned int baseRegister =
1570 vertexShaderD3D->getInterfaceBlockRegister(uniformBlock.name);
Jamie Madill4a3c2342015-10-08 12:58:45 -04001571 d3dUniformBlock.vsRegisterIndex = baseRegister + uniformBlockElement;
Jamie Madill62d31cb2015-09-11 13:25:51 -04001572 }
1573
1574 if (uniformBlock.fragmentStaticUse)
1575 {
1576 unsigned int baseRegister =
1577 fragmentShaderD3D->getInterfaceBlockRegister(uniformBlock.name);
Jamie Madill4a3c2342015-10-08 12:58:45 -04001578 d3dUniformBlock.psRegisterIndex = baseRegister + uniformBlockElement;
Jamie Madill62d31cb2015-09-11 13:25:51 -04001579 }
1580
Jamie Madill4a3c2342015-10-08 12:58:45 -04001581 mD3DUniformBlocks.push_back(d3dUniformBlock);
Jamie Madill62d31cb2015-09-11 13:25:51 -04001582 }
1583}
1584
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001585void ProgramD3D::initializeUniformStorage()
Brandon Jonesc9610c52014-08-25 17:02:59 -07001586{
1587 // Compute total default block size
Jamie Madill334d6152015-10-22 14:00:28 -04001588 unsigned int vertexRegisters = 0;
Brandon Jonesc9610c52014-08-25 17:02:59 -07001589 unsigned int fragmentRegisters = 0;
Jamie Madill62d31cb2015-09-11 13:25:51 -04001590 for (const D3DUniform *d3dUniform : mD3DUniforms)
Brandon Jonesc9610c52014-08-25 17:02:59 -07001591 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04001592 if (!d3dUniform->isSampler())
Brandon Jonesc9610c52014-08-25 17:02:59 -07001593 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04001594 if (d3dUniform->isReferencedByVertexShader())
Brandon Jonesc9610c52014-08-25 17:02:59 -07001595 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04001596 vertexRegisters = std::max(vertexRegisters,
1597 d3dUniform->vsRegisterIndex + d3dUniform->registerCount);
Brandon Jonesc9610c52014-08-25 17:02:59 -07001598 }
Jamie Madill62d31cb2015-09-11 13:25:51 -04001599 if (d3dUniform->isReferencedByFragmentShader())
Brandon Jonesc9610c52014-08-25 17:02:59 -07001600 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04001601 fragmentRegisters = std::max(
1602 fragmentRegisters, d3dUniform->psRegisterIndex + d3dUniform->registerCount);
Brandon Jonesc9610c52014-08-25 17:02:59 -07001603 }
1604 }
1605 }
1606
Jamie Madill334d6152015-10-22 14:00:28 -04001607 mVertexUniformStorage = mRenderer->createUniformStorage(vertexRegisters * 16u);
Brandon Jonesc9610c52014-08-25 17:02:59 -07001608 mFragmentUniformStorage = mRenderer->createUniformStorage(fragmentRegisters * 16u);
1609}
1610
Jamie Madill3e14e2b2015-10-29 14:38:53 -04001611gl::Error ProgramD3D::applyUniforms(GLenum drawMode)
Brandon Jones18bd4102014-09-22 14:21:44 -07001612{
Olli Etuahoe5df3062015-11-18 13:45:19 +02001613 ASSERT(!mDirtySamplerMapping);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001614
Jamie Madill01074252016-11-28 15:55:51 -05001615 ANGLE_TRY(mRenderer->applyUniforms(*this, drawMode, mD3DUniforms));
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001616
Jamie Madill62d31cb2015-09-11 13:25:51 -04001617 for (D3DUniform *d3dUniform : mD3DUniforms)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001618 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04001619 d3dUniform->dirty = false;
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001620 }
1621
1622 return gl::Error(GL_NO_ERROR);
Brandon Jones18bd4102014-09-22 14:21:44 -07001623}
1624
Jamie Madill9082b982016-04-27 15:21:51 -04001625gl::Error ProgramD3D::applyUniformBuffers(const gl::ContextState &data)
Brandon Jones18bd4102014-09-22 14:21:44 -07001626{
Jamie Madill48ef11b2016-04-27 15:21:52 -04001627 if (mState.getUniformBlocks().empty())
Jamie Madill4a3c2342015-10-08 12:58:45 -04001628 {
1629 return gl::Error(GL_NO_ERROR);
1630 }
1631
1632 // Lazy init.
1633 if (mD3DUniformBlocks.empty())
1634 {
1635 assignUniformBlockRegisters();
1636 }
1637
Jamie Madill03260fa2015-06-22 13:57:22 -04001638 mVertexUBOCache.clear();
1639 mFragmentUBOCache.clear();
Brandon Jones18bd4102014-09-22 14:21:44 -07001640
1641 const unsigned int reservedBuffersInVS = mRenderer->getReservedVertexUniformBuffers();
1642 const unsigned int reservedBuffersInFS = mRenderer->getReservedFragmentUniformBuffers();
1643
Jamie Madill4a3c2342015-10-08 12:58:45 -04001644 for (unsigned int uniformBlockIndex = 0; uniformBlockIndex < mD3DUniformBlocks.size();
Jamie Madill62d31cb2015-09-11 13:25:51 -04001645 uniformBlockIndex++)
Brandon Jones18bd4102014-09-22 14:21:44 -07001646 {
Jamie Madill4a3c2342015-10-08 12:58:45 -04001647 const D3DUniformBlock &uniformBlock = mD3DUniformBlocks[uniformBlockIndex];
Jamie Madill48ef11b2016-04-27 15:21:52 -04001648 GLuint blockBinding = mState.getUniformBlockBinding(uniformBlockIndex);
Brandon Jones18bd4102014-09-22 14:21:44 -07001649
Brandon Jones18bd4102014-09-22 14:21:44 -07001650 // Unnecessary to apply an unreferenced standard or shared UBO
Jamie Madill4a3c2342015-10-08 12:58:45 -04001651 if (!uniformBlock.vertexStaticUse() && !uniformBlock.fragmentStaticUse())
Brandon Jones18bd4102014-09-22 14:21:44 -07001652 {
1653 continue;
1654 }
1655
Jamie Madill4a3c2342015-10-08 12:58:45 -04001656 if (uniformBlock.vertexStaticUse())
Brandon Jones18bd4102014-09-22 14:21:44 -07001657 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04001658 unsigned int registerIndex = uniformBlock.vsRegisterIndex - reservedBuffersInVS;
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001659 ASSERT(registerIndex < data.getCaps().maxVertexUniformBlocks);
Jamie Madill03260fa2015-06-22 13:57:22 -04001660
Jamie Madill969194d2015-07-20 14:36:56 -04001661 if (mVertexUBOCache.size() <= registerIndex)
Jamie Madill03260fa2015-06-22 13:57:22 -04001662 {
1663 mVertexUBOCache.resize(registerIndex + 1, -1);
1664 }
1665
1666 ASSERT(mVertexUBOCache[registerIndex] == -1);
1667 mVertexUBOCache[registerIndex] = blockBinding;
Brandon Jones18bd4102014-09-22 14:21:44 -07001668 }
1669
Jamie Madill4a3c2342015-10-08 12:58:45 -04001670 if (uniformBlock.fragmentStaticUse())
Brandon Jones18bd4102014-09-22 14:21:44 -07001671 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04001672 unsigned int registerIndex = uniformBlock.psRegisterIndex - reservedBuffersInFS;
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001673 ASSERT(registerIndex < data.getCaps().maxFragmentUniformBlocks);
Jamie Madill03260fa2015-06-22 13:57:22 -04001674
1675 if (mFragmentUBOCache.size() <= registerIndex)
1676 {
1677 mFragmentUBOCache.resize(registerIndex + 1, -1);
1678 }
1679
1680 ASSERT(mFragmentUBOCache[registerIndex] == -1);
1681 mFragmentUBOCache[registerIndex] = blockBinding;
Brandon Jones18bd4102014-09-22 14:21:44 -07001682 }
1683 }
1684
Jamie Madill03260fa2015-06-22 13:57:22 -04001685 return mRenderer->setUniformBuffers(data, mVertexUBOCache, mFragmentUBOCache);
Brandon Jones18bd4102014-09-22 14:21:44 -07001686}
1687
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001688void ProgramD3D::dirtyAllUniforms()
Brandon Jones18bd4102014-09-22 14:21:44 -07001689{
Jamie Madill62d31cb2015-09-11 13:25:51 -04001690 for (D3DUniform *d3dUniform : mD3DUniforms)
Brandon Jones18bd4102014-09-22 14:21:44 -07001691 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04001692 d3dUniform->dirty = true;
Brandon Jones18bd4102014-09-22 14:21:44 -07001693 }
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001694}
1695
Jamie Madill334d6152015-10-22 14:00:28 -04001696void ProgramD3D::setUniform1fv(GLint location, GLsizei count, const GLfloat *v)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001697{
1698 setUniform(location, count, v, GL_FLOAT);
1699}
1700
1701void ProgramD3D::setUniform2fv(GLint location, GLsizei count, const GLfloat *v)
1702{
1703 setUniform(location, count, v, GL_FLOAT_VEC2);
1704}
1705
1706void ProgramD3D::setUniform3fv(GLint location, GLsizei count, const GLfloat *v)
1707{
1708 setUniform(location, count, v, GL_FLOAT_VEC3);
1709}
1710
1711void ProgramD3D::setUniform4fv(GLint location, GLsizei count, const GLfloat *v)
1712{
1713 setUniform(location, count, v, GL_FLOAT_VEC4);
1714}
1715
Jamie Madill334d6152015-10-22 14:00:28 -04001716void ProgramD3D::setUniformMatrix2fv(GLint location,
1717 GLsizei count,
1718 GLboolean transpose,
1719 const GLfloat *value)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001720{
1721 setUniformMatrixfv<2, 2>(location, count, transpose, value, GL_FLOAT_MAT2);
1722}
1723
Jamie Madill334d6152015-10-22 14:00:28 -04001724void ProgramD3D::setUniformMatrix3fv(GLint location,
1725 GLsizei count,
1726 GLboolean transpose,
1727 const GLfloat *value)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001728{
1729 setUniformMatrixfv<3, 3>(location, count, transpose, value, GL_FLOAT_MAT3);
1730}
1731
Jamie Madill334d6152015-10-22 14:00:28 -04001732void ProgramD3D::setUniformMatrix4fv(GLint location,
1733 GLsizei count,
1734 GLboolean transpose,
1735 const GLfloat *value)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001736{
1737 setUniformMatrixfv<4, 4>(location, count, transpose, value, GL_FLOAT_MAT4);
1738}
1739
Jamie Madill334d6152015-10-22 14:00:28 -04001740void ProgramD3D::setUniformMatrix2x3fv(GLint location,
1741 GLsizei count,
1742 GLboolean transpose,
1743 const GLfloat *value)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001744{
1745 setUniformMatrixfv<2, 3>(location, count, transpose, value, GL_FLOAT_MAT2x3);
1746}
1747
Jamie Madill334d6152015-10-22 14:00:28 -04001748void ProgramD3D::setUniformMatrix3x2fv(GLint location,
1749 GLsizei count,
1750 GLboolean transpose,
1751 const GLfloat *value)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001752{
1753 setUniformMatrixfv<3, 2>(location, count, transpose, value, GL_FLOAT_MAT3x2);
1754}
1755
Jamie Madill334d6152015-10-22 14:00:28 -04001756void ProgramD3D::setUniformMatrix2x4fv(GLint location,
1757 GLsizei count,
1758 GLboolean transpose,
1759 const GLfloat *value)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001760{
1761 setUniformMatrixfv<2, 4>(location, count, transpose, value, GL_FLOAT_MAT2x4);
1762}
1763
Jamie Madill334d6152015-10-22 14:00:28 -04001764void ProgramD3D::setUniformMatrix4x2fv(GLint location,
1765 GLsizei count,
1766 GLboolean transpose,
1767 const GLfloat *value)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001768{
1769 setUniformMatrixfv<4, 2>(location, count, transpose, value, GL_FLOAT_MAT4x2);
1770}
1771
Jamie Madill334d6152015-10-22 14:00:28 -04001772void ProgramD3D::setUniformMatrix3x4fv(GLint location,
1773 GLsizei count,
1774 GLboolean transpose,
1775 const GLfloat *value)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001776{
1777 setUniformMatrixfv<3, 4>(location, count, transpose, value, GL_FLOAT_MAT3x4);
1778}
1779
Jamie Madill334d6152015-10-22 14:00:28 -04001780void ProgramD3D::setUniformMatrix4x3fv(GLint location,
1781 GLsizei count,
1782 GLboolean transpose,
1783 const GLfloat *value)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001784{
1785 setUniformMatrixfv<4, 3>(location, count, transpose, value, GL_FLOAT_MAT4x3);
1786}
1787
1788void ProgramD3D::setUniform1iv(GLint location, GLsizei count, const GLint *v)
1789{
1790 setUniform(location, count, v, GL_INT);
1791}
1792
1793void ProgramD3D::setUniform2iv(GLint location, GLsizei count, const GLint *v)
1794{
1795 setUniform(location, count, v, GL_INT_VEC2);
1796}
1797
1798void ProgramD3D::setUniform3iv(GLint location, GLsizei count, const GLint *v)
1799{
1800 setUniform(location, count, v, GL_INT_VEC3);
1801}
1802
1803void ProgramD3D::setUniform4iv(GLint location, GLsizei count, const GLint *v)
1804{
1805 setUniform(location, count, v, GL_INT_VEC4);
1806}
1807
1808void ProgramD3D::setUniform1uiv(GLint location, GLsizei count, const GLuint *v)
1809{
1810 setUniform(location, count, v, GL_UNSIGNED_INT);
1811}
1812
1813void ProgramD3D::setUniform2uiv(GLint location, GLsizei count, const GLuint *v)
1814{
1815 setUniform(location, count, v, GL_UNSIGNED_INT_VEC2);
1816}
1817
1818void ProgramD3D::setUniform3uiv(GLint location, GLsizei count, const GLuint *v)
1819{
1820 setUniform(location, count, v, GL_UNSIGNED_INT_VEC3);
1821}
1822
1823void ProgramD3D::setUniform4uiv(GLint location, GLsizei count, const GLuint *v)
1824{
1825 setUniform(location, count, v, GL_UNSIGNED_INT_VEC4);
1826}
1827
Jamie Madill4a3c2342015-10-08 12:58:45 -04001828void ProgramD3D::setUniformBlockBinding(GLuint /*uniformBlockIndex*/,
1829 GLuint /*uniformBlockBinding*/)
Geoff Lang5d124a62015-09-15 13:03:27 -04001830{
1831}
1832
Jamie Madill3d3d2f22015-09-23 16:47:51 -04001833void ProgramD3D::defineUniformsAndAssignRegisters()
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001834{
Jamie Madill3d3d2f22015-09-23 16:47:51 -04001835 D3DUniformMap uniformMap;
Jamie Madill48ef11b2016-04-27 15:21:52 -04001836 const gl::Shader *vertexShader = mState.getAttachedVertexShader();
Jamie Madill62d31cb2015-09-11 13:25:51 -04001837 for (const sh::Uniform &vertexUniform : vertexShader->getUniforms())
Jamie Madillfb536032015-09-11 13:19:49 -04001838
Jamie Madilla2eb02c2015-09-11 12:31:41 +00001839 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04001840 if (vertexUniform.staticUse)
Jamie Madillfb536032015-09-11 13:19:49 -04001841 {
Jamie Madill91445bc2015-09-23 16:47:53 -04001842 defineUniformBase(vertexShader, vertexUniform, &uniformMap);
Jamie Madillfb536032015-09-11 13:19:49 -04001843 }
1844 }
1845
Jamie Madill48ef11b2016-04-27 15:21:52 -04001846 const gl::Shader *fragmentShader = mState.getAttachedFragmentShader();
Jamie Madill62d31cb2015-09-11 13:25:51 -04001847 for (const sh::Uniform &fragmentUniform : fragmentShader->getUniforms())
Jamie Madillfb536032015-09-11 13:19:49 -04001848 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04001849 if (fragmentUniform.staticUse)
Jamie Madillfb536032015-09-11 13:19:49 -04001850 {
Jamie Madill91445bc2015-09-23 16:47:53 -04001851 defineUniformBase(fragmentShader, fragmentUniform, &uniformMap);
Jamie Madillfb536032015-09-11 13:19:49 -04001852 }
1853 }
1854
Jamie Madill3d3d2f22015-09-23 16:47:51 -04001855 // Initialize the D3DUniform list to mirror the indexing of the GL layer.
Jamie Madill48ef11b2016-04-27 15:21:52 -04001856 for (const gl::LinkedUniform &glUniform : mState.getUniforms())
Jamie Madill3d3d2f22015-09-23 16:47:51 -04001857 {
1858 if (!glUniform.isInDefaultBlock())
1859 continue;
1860
1861 auto mapEntry = uniformMap.find(glUniform.name);
1862 ASSERT(mapEntry != uniformMap.end());
1863 mD3DUniforms.push_back(mapEntry->second);
1864 }
1865
Jamie Madill62d31cb2015-09-11 13:25:51 -04001866 assignAllSamplerRegisters();
Jamie Madillfb536032015-09-11 13:19:49 -04001867 initializeUniformStorage();
Jamie Madillfb536032015-09-11 13:19:49 -04001868}
1869
Jamie Madill91445bc2015-09-23 16:47:53 -04001870void ProgramD3D::defineUniformBase(const gl::Shader *shader,
Jamie Madill3d3d2f22015-09-23 16:47:51 -04001871 const sh::Uniform &uniform,
1872 D3DUniformMap *uniformMap)
Jamie Madillfb536032015-09-11 13:19:49 -04001873{
Olli Etuaho96963162016-03-21 11:54:33 +02001874 // Samplers get their registers assigned in assignAllSamplerRegisters.
1875 if (uniform.isBuiltIn() || gl::IsSamplerType(uniform.type))
Jamie Madillfb536032015-09-11 13:19:49 -04001876 {
Jamie Madill91445bc2015-09-23 16:47:53 -04001877 defineUniform(shader->getType(), uniform, uniform.name, nullptr, uniformMap);
Jamie Madill55def582015-05-04 11:24:57 -04001878 return;
1879 }
1880
Jamie Madill91445bc2015-09-23 16:47:53 -04001881 const ShaderD3D *shaderD3D = GetImplAs<ShaderD3D>(shader);
1882
1883 unsigned int startRegister = shaderD3D->getUniformRegister(uniform.name);
1884 ShShaderOutput outputType = shaderD3D->getCompilerOutputType();
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001885 sh::HLSLBlockEncoder encoder(sh::HLSLBlockEncoder::GetStrategyFor(outputType));
Jamie Madill62d31cb2015-09-11 13:25:51 -04001886 encoder.skipRegisters(startRegister);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001887
Jamie Madill91445bc2015-09-23 16:47:53 -04001888 defineUniform(shader->getType(), uniform, uniform.name, &encoder, uniformMap);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001889}
1890
Jamie Madill62d31cb2015-09-11 13:25:51 -04001891D3DUniform *ProgramD3D::getD3DUniformByName(const std::string &name)
1892{
1893 for (D3DUniform *d3dUniform : mD3DUniforms)
1894 {
1895 if (d3dUniform->name == name)
1896 {
1897 return d3dUniform;
1898 }
1899 }
1900
1901 return nullptr;
1902}
1903
Jamie Madill91445bc2015-09-23 16:47:53 -04001904void ProgramD3D::defineUniform(GLenum shaderType,
Jamie Madill3d3d2f22015-09-23 16:47:51 -04001905 const sh::ShaderVariable &uniform,
1906 const std::string &fullName,
1907 sh::HLSLBlockEncoder *encoder,
1908 D3DUniformMap *uniformMap)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001909{
1910 if (uniform.isStruct())
1911 {
1912 for (unsigned int elementIndex = 0; elementIndex < uniform.elementCount(); elementIndex++)
1913 {
1914 const std::string &elementString = (uniform.isArray() ? ArrayString(elementIndex) : "");
1915
Jamie Madill55def582015-05-04 11:24:57 -04001916 if (encoder)
1917 encoder->enterAggregateType();
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001918
1919 for (size_t fieldIndex = 0; fieldIndex < uniform.fields.size(); fieldIndex++)
1920 {
Jamie Madill334d6152015-10-22 14:00:28 -04001921 const sh::ShaderVariable &field = uniform.fields[fieldIndex];
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001922 const std::string &fieldFullName = (fullName + elementString + "." + field.name);
1923
Olli Etuaho96963162016-03-21 11:54:33 +02001924 // Samplers get their registers assigned in assignAllSamplerRegisters.
1925 // Also they couldn't use the same encoder as the rest of the struct, since they are
1926 // extracted out of the struct by the shader translator.
1927 if (gl::IsSamplerType(field.type))
1928 {
1929 defineUniform(shaderType, field, fieldFullName, nullptr, uniformMap);
1930 }
1931 else
1932 {
1933 defineUniform(shaderType, field, fieldFullName, encoder, uniformMap);
1934 }
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001935 }
1936
Jamie Madill55def582015-05-04 11:24:57 -04001937 if (encoder)
1938 encoder->exitAggregateType();
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001939 }
Jamie Madill62d31cb2015-09-11 13:25:51 -04001940 return;
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001941 }
Jamie Madill62d31cb2015-09-11 13:25:51 -04001942
1943 // Not a struct. Arrays are treated as aggregate types.
1944 if (uniform.isArray() && encoder)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001945 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04001946 encoder->enterAggregateType();
1947 }
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001948
Jamie Madill62d31cb2015-09-11 13:25:51 -04001949 // Advance the uniform offset, to track registers allocation for structs
1950 sh::BlockMemberInfo blockInfo =
1951 encoder ? encoder->encodeType(uniform.type, uniform.arraySize, false)
1952 : sh::BlockMemberInfo::getDefaultBlockInfo();
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001953
Jamie Madill3d3d2f22015-09-23 16:47:51 -04001954 auto uniformMapEntry = uniformMap->find(fullName);
1955 D3DUniform *d3dUniform = nullptr;
Jamie Madill2857f482015-02-09 15:35:29 -05001956
Jamie Madill3d3d2f22015-09-23 16:47:51 -04001957 if (uniformMapEntry != uniformMap->end())
Jamie Madill62d31cb2015-09-11 13:25:51 -04001958 {
Jamie Madill3d3d2f22015-09-23 16:47:51 -04001959 d3dUniform = uniformMapEntry->second;
1960 }
1961 else
1962 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04001963 d3dUniform = new D3DUniform(uniform.type, fullName, uniform.arraySize, true);
Jamie Madill3d3d2f22015-09-23 16:47:51 -04001964 (*uniformMap)[fullName] = d3dUniform;
Jamie Madill62d31cb2015-09-11 13:25:51 -04001965 }
1966
1967 if (encoder)
1968 {
Jamie Madill3d3d2f22015-09-23 16:47:51 -04001969 d3dUniform->registerElement =
1970 static_cast<unsigned int>(sh::HLSLBlockEncoder::getBlockRegisterElement(blockInfo));
Jamie Madill62d31cb2015-09-11 13:25:51 -04001971 unsigned int reg =
1972 static_cast<unsigned int>(sh::HLSLBlockEncoder::getBlockRegister(blockInfo));
Jamie Madill91445bc2015-09-23 16:47:53 -04001973 if (shaderType == GL_FRAGMENT_SHADER)
Jamie Madill62d31cb2015-09-11 13:25:51 -04001974 {
1975 d3dUniform->psRegisterIndex = reg;
1976 }
Jamie Madill91445bc2015-09-23 16:47:53 -04001977 else
Jamie Madill62d31cb2015-09-11 13:25:51 -04001978 {
Jamie Madill91445bc2015-09-23 16:47:53 -04001979 ASSERT(shaderType == GL_VERTEX_SHADER);
Jamie Madill62d31cb2015-09-11 13:25:51 -04001980 d3dUniform->vsRegisterIndex = reg;
1981 }
Jamie Madillfb536032015-09-11 13:19:49 -04001982
1983 // Arrays are treated as aggregate types
Jamie Madill62d31cb2015-09-11 13:25:51 -04001984 if (uniform.isArray())
Jamie Madillfb536032015-09-11 13:19:49 -04001985 {
1986 encoder->exitAggregateType();
1987 }
1988 }
1989}
1990
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001991template <typename T>
Jamie Madill62d31cb2015-09-11 13:25:51 -04001992void ProgramD3D::setUniform(GLint location, GLsizei countIn, const T *v, GLenum targetUniformType)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001993{
Jamie Madill334d6152015-10-22 14:00:28 -04001994 const int components = gl::VariableComponentCount(targetUniformType);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001995 const GLenum targetBoolType = gl::VariableBoolVectorType(targetUniformType);
1996
Jamie Madill62d31cb2015-09-11 13:25:51 -04001997 D3DUniform *targetUniform = getD3DUniformFromLocation(location);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001998
Jamie Madill62d31cb2015-09-11 13:25:51 -04001999 unsigned int elementCount = targetUniform->elementCount();
Jamie Madill48ef11b2016-04-27 15:21:52 -04002000 unsigned int arrayElement = mState.getUniformLocations()[location].element;
Jamie Madill62d31cb2015-09-11 13:25:51 -04002001 unsigned int count = std::min(elementCount - arrayElement, static_cast<unsigned int>(countIn));
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002002
2003 if (targetUniform->type == targetUniformType)
2004 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04002005 T *target = reinterpret_cast<T *>(targetUniform->data) + arrayElement * 4;
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002006
Jamie Madill62d31cb2015-09-11 13:25:51 -04002007 for (unsigned int i = 0; i < count; i++)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002008 {
Jamie Madill334d6152015-10-22 14:00:28 -04002009 T *dest = target + (i * 4);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002010 const T *source = v + (i * components);
2011
2012 for (int c = 0; c < components; c++)
2013 {
2014 SetIfDirty(dest + c, source[c], &targetUniform->dirty);
2015 }
2016 for (int c = components; c < 4; c++)
2017 {
2018 SetIfDirty(dest + c, T(0), &targetUniform->dirty);
2019 }
2020 }
2021 }
2022 else if (targetUniform->type == targetBoolType)
2023 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04002024 GLint *boolParams = reinterpret_cast<GLint *>(targetUniform->data) + arrayElement * 4;
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002025
Jamie Madill62d31cb2015-09-11 13:25:51 -04002026 for (unsigned int i = 0; i < count; i++)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002027 {
Jamie Madill334d6152015-10-22 14:00:28 -04002028 GLint *dest = boolParams + (i * 4);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002029 const T *source = v + (i * components);
2030
2031 for (int c = 0; c < components; c++)
2032 {
Jamie Madill334d6152015-10-22 14:00:28 -04002033 SetIfDirty(dest + c, (source[c] == static_cast<T>(0)) ? GL_FALSE : GL_TRUE,
2034 &targetUniform->dirty);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002035 }
2036 for (int c = components; c < 4; c++)
2037 {
2038 SetIfDirty(dest + c, GL_FALSE, &targetUniform->dirty);
2039 }
2040 }
2041 }
Jamie Madill62d31cb2015-09-11 13:25:51 -04002042 else if (targetUniform->isSampler())
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002043 {
2044 ASSERT(targetUniformType == GL_INT);
2045
Jamie Madill62d31cb2015-09-11 13:25:51 -04002046 GLint *target = reinterpret_cast<GLint *>(targetUniform->data) + arrayElement * 4;
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002047
2048 bool wasDirty = targetUniform->dirty;
2049
Jamie Madill62d31cb2015-09-11 13:25:51 -04002050 for (unsigned int i = 0; i < count; i++)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002051 {
Jamie Madill334d6152015-10-22 14:00:28 -04002052 GLint *dest = target + (i * 4);
2053 const GLint *source = reinterpret_cast<const GLint *>(v) + (i * components);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002054
2055 SetIfDirty(dest + 0, source[0], &targetUniform->dirty);
2056 SetIfDirty(dest + 1, 0, &targetUniform->dirty);
2057 SetIfDirty(dest + 2, 0, &targetUniform->dirty);
2058 SetIfDirty(dest + 3, 0, &targetUniform->dirty);
2059 }
2060
2061 if (!wasDirty && targetUniform->dirty)
2062 {
2063 mDirtySamplerMapping = true;
2064 }
Brandon Jones18bd4102014-09-22 14:21:44 -07002065 }
Jamie Madill334d6152015-10-22 14:00:28 -04002066 else
2067 UNREACHABLE();
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002068}
2069
2070template <int cols, int rows>
Jamie Madill62d31cb2015-09-11 13:25:51 -04002071void ProgramD3D::setUniformMatrixfv(GLint location,
2072 GLsizei countIn,
2073 GLboolean transpose,
2074 const GLfloat *value,
2075 GLenum targetUniformType)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002076{
Jamie Madill62d31cb2015-09-11 13:25:51 -04002077 D3DUniform *targetUniform = getD3DUniformFromLocation(location);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002078
Jamie Madill62d31cb2015-09-11 13:25:51 -04002079 unsigned int elementCount = targetUniform->elementCount();
Jamie Madill48ef11b2016-04-27 15:21:52 -04002080 unsigned int arrayElement = mState.getUniformLocations()[location].element;
Jamie Madill62d31cb2015-09-11 13:25:51 -04002081 unsigned int count = std::min(elementCount - arrayElement, static_cast<unsigned int>(countIn));
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002082
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002083 const unsigned int targetMatrixStride = (4 * rows);
Jamie Madill62d31cb2015-09-11 13:25:51 -04002084 GLfloat *target =
2085 (GLfloat *)(targetUniform->data + arrayElement * sizeof(GLfloat) * targetMatrixStride);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002086
Jamie Madill62d31cb2015-09-11 13:25:51 -04002087 for (unsigned int i = 0; i < count; i++)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002088 {
2089 // Internally store matrices as transposed versions to accomodate HLSL matrix indexing
2090 if (transpose == GL_FALSE)
2091 {
Jamie Madill334d6152015-10-22 14:00:28 -04002092 targetUniform->dirty = TransposeMatrix<GLfloat>(target, value, 4, rows, rows, cols) ||
2093 targetUniform->dirty;
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002094 }
2095 else
2096 {
Jamie Madill334d6152015-10-22 14:00:28 -04002097 targetUniform->dirty =
2098 ExpandMatrix<GLfloat>(target, value, 4, rows, cols, rows) || targetUniform->dirty;
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002099 }
2100 target += targetMatrixStride;
2101 value += cols * rows;
2102 }
2103}
2104
Jamie Madill4a3c2342015-10-08 12:58:45 -04002105size_t ProgramD3D::getUniformBlockInfo(const sh::InterfaceBlock &interfaceBlock)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002106{
Jamie Madill62d31cb2015-09-11 13:25:51 -04002107 ASSERT(interfaceBlock.staticUse || interfaceBlock.layout != sh::BLOCKLAYOUT_PACKED);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002108
Jamie Madill62d31cb2015-09-11 13:25:51 -04002109 // define member uniforms
2110 sh::Std140BlockEncoder std140Encoder;
2111 sh::HLSLBlockEncoder hlslEncoder(sh::HLSLBlockEncoder::ENCODE_PACKED);
2112 sh::BlockLayoutEncoder *encoder = nullptr;
2113
2114 if (interfaceBlock.layout == sh::BLOCKLAYOUT_STANDARD)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002115 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04002116 encoder = &std140Encoder;
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002117 }
2118 else
2119 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04002120 encoder = &hlslEncoder;
Jamie Madill61b8dd92015-09-09 19:04:04 +00002121 }
Jamie Madill62d31cb2015-09-11 13:25:51 -04002122
Jamie Madill39046162016-02-08 15:05:17 -05002123 GetUniformBlockInfo(interfaceBlock.fields, interfaceBlock.fieldPrefix(), encoder,
2124 interfaceBlock.isRowMajorLayout, &mBlockInfo);
Jamie Madill62d31cb2015-09-11 13:25:51 -04002125
2126 return encoder->getBlockSize();
Jamie Madill61b8dd92015-09-09 19:04:04 +00002127}
2128
Jamie Madill62d31cb2015-09-11 13:25:51 -04002129void ProgramD3D::assignAllSamplerRegisters()
Jamie Madilla2eb02c2015-09-11 12:31:41 +00002130{
Olli Etuaho96963162016-03-21 11:54:33 +02002131 for (D3DUniform *d3dUniform : mD3DUniforms)
Jamie Madilla2eb02c2015-09-11 12:31:41 +00002132 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04002133 if (d3dUniform->isSampler())
Jamie Madillfb536032015-09-11 13:19:49 -04002134 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04002135 assignSamplerRegisters(d3dUniform);
Jamie Madillfb536032015-09-11 13:19:49 -04002136 }
Jamie Madilla2eb02c2015-09-11 12:31:41 +00002137 }
2138}
2139
Olli Etuaho96963162016-03-21 11:54:33 +02002140void ProgramD3D::assignSamplerRegisters(D3DUniform *d3dUniform)
Jamie Madillfb536032015-09-11 13:19:49 -04002141{
Jamie Madill62d31cb2015-09-11 13:25:51 -04002142 ASSERT(d3dUniform->isSampler());
Jamie Madill48ef11b2016-04-27 15:21:52 -04002143 const ShaderD3D *vertexShaderD3D = GetImplAs<ShaderD3D>(mState.getAttachedVertexShader());
2144 const ShaderD3D *fragmentShaderD3D = GetImplAs<ShaderD3D>(mState.getAttachedFragmentShader());
Olli Etuaho96963162016-03-21 11:54:33 +02002145 ASSERT(vertexShaderD3D->hasUniform(d3dUniform) || fragmentShaderD3D->hasUniform(d3dUniform));
2146 if (vertexShaderD3D->hasUniform(d3dUniform))
Jamie Madillfb536032015-09-11 13:19:49 -04002147 {
Olli Etuaho96963162016-03-21 11:54:33 +02002148 d3dUniform->vsRegisterIndex = vertexShaderD3D->getUniformRegister(d3dUniform->name);
2149 ASSERT(d3dUniform->vsRegisterIndex != GL_INVALID_INDEX);
Jamie Madill62d31cb2015-09-11 13:25:51 -04002150 AssignSamplers(d3dUniform->vsRegisterIndex, d3dUniform->type, d3dUniform->arraySize,
2151 mSamplersVS, &mUsedVertexSamplerRange);
Jamie Madillfb536032015-09-11 13:19:49 -04002152 }
Olli Etuaho96963162016-03-21 11:54:33 +02002153 if (fragmentShaderD3D->hasUniform(d3dUniform))
Jamie Madillfb536032015-09-11 13:19:49 -04002154 {
Olli Etuaho96963162016-03-21 11:54:33 +02002155 d3dUniform->psRegisterIndex = fragmentShaderD3D->getUniformRegister(d3dUniform->name);
2156 ASSERT(d3dUniform->psRegisterIndex != GL_INVALID_INDEX);
Jamie Madill62d31cb2015-09-11 13:25:51 -04002157 AssignSamplers(d3dUniform->psRegisterIndex, d3dUniform->type, d3dUniform->arraySize,
2158 mSamplersPS, &mUsedPixelSamplerRange);
Jamie Madillfb536032015-09-11 13:19:49 -04002159 }
2160}
2161
Jamie Madill62d31cb2015-09-11 13:25:51 -04002162// static
2163void ProgramD3D::AssignSamplers(unsigned int startSamplerIndex,
Jamie Madilld3dfda22015-07-06 08:28:49 -04002164 GLenum samplerType,
2165 unsigned int samplerCount,
2166 std::vector<Sampler> &outSamplers,
2167 GLuint *outUsedRange)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002168{
2169 unsigned int samplerIndex = startSamplerIndex;
2170
2171 do
2172 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04002173 ASSERT(samplerIndex < outSamplers.size());
2174 Sampler *sampler = &outSamplers[samplerIndex];
2175 sampler->active = true;
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002176 sampler->textureType = gl::SamplerTypeToTextureType(samplerType);
Jamie Madill62d31cb2015-09-11 13:25:51 -04002177 sampler->logicalTextureUnit = 0;
2178 *outUsedRange = std::max(samplerIndex + 1, *outUsedRange);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002179 samplerIndex++;
2180 } while (samplerIndex < startSamplerIndex + samplerCount);
Brandon Jones18bd4102014-09-22 14:21:44 -07002181}
2182
Brandon Jonesc9610c52014-08-25 17:02:59 -07002183void ProgramD3D::reset()
2184{
Brandon Joneseb994362014-09-24 10:27:28 -07002185 SafeDeleteContainer(mVertexExecutables);
2186 SafeDeleteContainer(mPixelExecutables);
Jamie Madill4e31ad52015-10-29 10:32:57 -04002187
2188 for (auto &element : mGeometryExecutables)
2189 {
2190 SafeDelete(element);
2191 }
Brandon Joneseb994362014-09-24 10:27:28 -07002192
Brandon Jones22502d52014-08-29 16:58:36 -07002193 mVertexHLSL.clear();
Geoff Lang6941a552015-07-27 11:06:45 -04002194 mVertexWorkarounds = D3DCompilerWorkarounds();
Brandon Jones22502d52014-08-29 16:58:36 -07002195
2196 mPixelHLSL.clear();
Geoff Lang6941a552015-07-27 11:06:45 -04002197 mPixelWorkarounds = D3DCompilerWorkarounds();
Brandon Jones22502d52014-08-29 16:58:36 -07002198 mUsesFragDepth = false;
2199 mPixelShaderKey.clear();
Brandon Jones44151a92014-09-10 11:32:25 -07002200 mUsesPointSize = false;
Jamie Madill3e14e2b2015-10-29 14:38:53 -04002201 mUsesFlatInterpolation = false;
Brandon Jones22502d52014-08-29 16:58:36 -07002202
Jamie Madill62d31cb2015-09-11 13:25:51 -04002203 SafeDeleteContainer(mD3DUniforms);
Jamie Madill4a3c2342015-10-08 12:58:45 -04002204 mD3DUniformBlocks.clear();
Jamie Madill62d31cb2015-09-11 13:25:51 -04002205
Brandon Jonesc9610c52014-08-25 17:02:59 -07002206 SafeDelete(mVertexUniformStorage);
2207 SafeDelete(mFragmentUniformStorage);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002208
2209 mSamplersPS.clear();
2210 mSamplersVS.clear();
2211
2212 mUsedVertexSamplerRange = 0;
Jamie Madill334d6152015-10-22 14:00:28 -04002213 mUsedPixelSamplerRange = 0;
2214 mDirtySamplerMapping = true;
Jamie Madill437d2662014-12-05 14:23:35 -05002215
Jamie Madill8047c0d2016-03-07 13:02:12 -05002216 mAttribLocationToD3DSemantic.fill(-1);
Jamie Madillccdf74b2015-08-18 10:46:12 -04002217
Jamie Madill9fc36822015-11-18 13:08:07 -05002218 mStreamOutVaryings.clear();
Jamie Madill4e31ad52015-10-29 10:32:57 -04002219
2220 mGeometryShaderPreamble.clear();
Brandon Jonesc9610c52014-08-25 17:02:59 -07002221}
2222
Geoff Lang7dd2e102014-11-10 15:19:26 -05002223unsigned int ProgramD3D::getSerial() const
2224{
2225 return mSerial;
2226}
2227
2228unsigned int ProgramD3D::issueSerial()
2229{
2230 return mCurrentSerial++;
2231}
2232
Jamie Madill8047c0d2016-03-07 13:02:12 -05002233void ProgramD3D::initAttribLocationsToD3DSemantic()
Jamie Madill63805b42015-08-25 13:17:39 -04002234{
Jamie Madill48ef11b2016-04-27 15:21:52 -04002235 const gl::Shader *vertexShader = mState.getAttachedVertexShader();
Jamie Madill63805b42015-08-25 13:17:39 -04002236 ASSERT(vertexShader != nullptr);
2237
2238 // Init semantic index
Jamie Madill48ef11b2016-04-27 15:21:52 -04002239 for (const sh::Attribute &attribute : mState.getAttributes())
Jamie Madill63805b42015-08-25 13:17:39 -04002240 {
Jamie Madill8047c0d2016-03-07 13:02:12 -05002241 int d3dSemantic = vertexShader->getSemanticIndex(attribute.name);
2242 int regCount = gl::VariableRegisterCount(attribute.type);
Jamie Madill63805b42015-08-25 13:17:39 -04002243
Jamie Madill8047c0d2016-03-07 13:02:12 -05002244 for (int reg = 0; reg < regCount; ++reg)
Jamie Madill63805b42015-08-25 13:17:39 -04002245 {
Jamie Madill8047c0d2016-03-07 13:02:12 -05002246 mAttribLocationToD3DSemantic[attribute.location + reg] = d3dSemantic + reg;
Jamie Madill63805b42015-08-25 13:17:39 -04002247 }
2248 }
Jamie Madill437d2662014-12-05 14:23:35 -05002249}
2250
Jamie Madill63805b42015-08-25 13:17:39 -04002251void ProgramD3D::updateCachedInputLayout(const gl::State &state)
Jamie Madilld3dfda22015-07-06 08:28:49 -04002252{
Jamie Madillbd136f92015-08-10 14:51:37 -04002253 mCachedInputLayout.clear();
Jamie Madilld3dfda22015-07-06 08:28:49 -04002254 const auto &vertexAttributes = state.getVertexArray()->getVertexAttributes();
Jamie Madillf8dd7b12015-08-05 13:50:08 -04002255
Jamie Madill01074252016-11-28 15:55:51 -05002256 for (unsigned int locationIndex : IterateBitSet(mState.getActiveAttribLocationsMask()))
Jamie Madilld3dfda22015-07-06 08:28:49 -04002257 {
Jamie Madill8047c0d2016-03-07 13:02:12 -05002258 int d3dSemantic = mAttribLocationToD3DSemantic[locationIndex];
Jamie Madilld3dfda22015-07-06 08:28:49 -04002259
Jamie Madill8047c0d2016-03-07 13:02:12 -05002260 if (d3dSemantic != -1)
Jamie Madilld3dfda22015-07-06 08:28:49 -04002261 {
Jamie Madill8047c0d2016-03-07 13:02:12 -05002262 if (mCachedInputLayout.size() < static_cast<size_t>(d3dSemantic + 1))
Jamie Madillbd136f92015-08-10 14:51:37 -04002263 {
Jamie Madill8047c0d2016-03-07 13:02:12 -05002264 mCachedInputLayout.resize(d3dSemantic + 1, gl::VERTEX_FORMAT_INVALID);
Jamie Madillbd136f92015-08-10 14:51:37 -04002265 }
Jamie Madill8047c0d2016-03-07 13:02:12 -05002266 mCachedInputLayout[d3dSemantic] =
2267 GetVertexFormatType(vertexAttributes[locationIndex],
2268 state.getVertexAttribCurrentValue(locationIndex).Type);
Jamie Madilld3dfda22015-07-06 08:28:49 -04002269 }
2270 }
2271}
2272
Jamie Madill9fc36822015-11-18 13:08:07 -05002273void ProgramD3D::gatherTransformFeedbackVaryings(const VaryingPacking &varyingPacking)
Jamie Madillccdf74b2015-08-18 10:46:12 -04002274{
Jamie Madill9fc36822015-11-18 13:08:07 -05002275 const auto &builtins = varyingPacking.builtins(SHADER_VERTEX);
2276
2277 const std::string &varyingSemantic =
2278 GetVaryingSemantic(mRenderer->getMajorShaderModel(), usesPointSize());
2279
Jamie Madillccdf74b2015-08-18 10:46:12 -04002280 // Gather the linked varyings that are used for transform feedback, they should all exist.
Jamie Madill9fc36822015-11-18 13:08:07 -05002281 mStreamOutVaryings.clear();
2282
Jamie Madill48ef11b2016-04-27 15:21:52 -04002283 const auto &tfVaryingNames = mState.getTransformFeedbackVaryingNames();
Jamie Madill9fc36822015-11-18 13:08:07 -05002284 for (unsigned int outputSlot = 0; outputSlot < static_cast<unsigned int>(tfVaryingNames.size());
2285 ++outputSlot)
Jamie Madillccdf74b2015-08-18 10:46:12 -04002286 {
Jamie Madill9fc36822015-11-18 13:08:07 -05002287 const auto &tfVaryingName = tfVaryingNames[outputSlot];
2288 if (tfVaryingName == "gl_Position")
Jamie Madillccdf74b2015-08-18 10:46:12 -04002289 {
Jamie Madill9fc36822015-11-18 13:08:07 -05002290 if (builtins.glPosition.enabled)
Jamie Madillccdf74b2015-08-18 10:46:12 -04002291 {
Jamie Madill9fc36822015-11-18 13:08:07 -05002292 mStreamOutVaryings.push_back(D3DVarying(builtins.glPosition.semantic,
2293 builtins.glPosition.index, 4, outputSlot));
2294 }
2295 }
2296 else if (tfVaryingName == "gl_FragCoord")
2297 {
2298 if (builtins.glFragCoord.enabled)
2299 {
2300 mStreamOutVaryings.push_back(D3DVarying(builtins.glFragCoord.semantic,
2301 builtins.glFragCoord.index, 4, outputSlot));
2302 }
2303 }
2304 else if (tfVaryingName == "gl_PointSize")
2305 {
2306 if (builtins.glPointSize.enabled)
2307 {
2308 mStreamOutVaryings.push_back(D3DVarying("PSIZE", 0, 1, outputSlot));
2309 }
2310 }
2311 else
2312 {
2313 for (const PackedVaryingRegister &registerInfo : varyingPacking.getRegisterList())
2314 {
Jamie Madill55c25d02015-11-18 13:08:08 -05002315 const auto &varying = *registerInfo.packedVarying->varying;
2316 GLenum transposedType = gl::TransposeMatrixType(varying.type);
Jamie Madill9fc36822015-11-18 13:08:07 -05002317 int componentCount = gl::VariableColumnCount(transposedType);
2318 ASSERT(!varying.isBuiltIn());
2319
Jamie Madill55c25d02015-11-18 13:08:08 -05002320 // Transform feedback for varying structs is underspecified.
2321 // See Khronos bug 9856.
2322 // TODO(jmadill): Figure out how to be spec-compliant here.
2323 if (registerInfo.packedVarying->isStructField() || varying.isStruct())
2324 continue;
2325
Jamie Madill9fc36822015-11-18 13:08:07 -05002326 // There can be more than one register assigned to a particular varying, and each
2327 // register needs its own stream out entry.
2328 if (tfVaryingName == varying.name)
2329 {
2330 mStreamOutVaryings.push_back(D3DVarying(
2331 varyingSemantic, registerInfo.semanticIndex, componentCount, outputSlot));
2332 }
Jamie Madillccdf74b2015-08-18 10:46:12 -04002333 }
2334 }
2335 }
2336}
Jamie Madill62d31cb2015-09-11 13:25:51 -04002337
2338D3DUniform *ProgramD3D::getD3DUniformFromLocation(GLint location)
2339{
Jamie Madill48ef11b2016-04-27 15:21:52 -04002340 return mD3DUniforms[mState.getUniformLocations()[location].index];
Jamie Madill62d31cb2015-09-11 13:25:51 -04002341}
Jamie Madill4a3c2342015-10-08 12:58:45 -04002342
2343bool ProgramD3D::getUniformBlockSize(const std::string &blockName, size_t *sizeOut) const
2344{
2345 std::string baseName = blockName;
2346 gl::ParseAndStripArrayIndex(&baseName);
2347
2348 auto sizeIter = mBlockDataSizes.find(baseName);
2349 if (sizeIter == mBlockDataSizes.end())
2350 {
2351 *sizeOut = 0;
2352 return false;
2353 }
2354
2355 *sizeOut = sizeIter->second;
2356 return true;
2357}
2358
2359bool ProgramD3D::getUniformBlockMemberInfo(const std::string &memberUniformName,
2360 sh::BlockMemberInfo *memberInfoOut) const
2361{
2362 auto infoIter = mBlockInfo.find(memberUniformName);
2363 if (infoIter == mBlockInfo.end())
2364 {
2365 *memberInfoOut = sh::BlockMemberInfo::getDefaultBlockInfo();
2366 return false;
2367 }
2368
2369 *memberInfoOut = infoIter->second;
2370 return true;
2371}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002372
2373void ProgramD3D::setPathFragmentInputGen(const std::string &inputName,
2374 GLenum genMode,
2375 GLint components,
2376 const GLfloat *coeffs)
2377{
2378 UNREACHABLE();
2379}
2380
Jamie Madill8047c0d2016-03-07 13:02:12 -05002381} // namespace rx