blob: 2875000f2a4001805fef28ea6eb45b75f5a0d3f2 [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
Jamie Madill20e005b2017-04-07 14:19:22 -040011#include "common/bitset_utils.h"
Jamie Madill437d2662014-12-05 14:23:35 -050012#include "common/utilities.h"
Jamie Madillc564c072017-06-01 12:45:42 -040013#include "libANGLE/Context.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050014#include "libANGLE/Framebuffer.h"
15#include "libANGLE/FramebufferAttachment.h"
16#include "libANGLE/Program.h"
Jamie Madill53ea9cc2016-05-17 10:12:52 -040017#include "libANGLE/Uniform.h"
Jamie Madill192745a2016-12-22 15:58:21 -050018#include "libANGLE/VaryingPacking.h"
Jamie Madilld3dfda22015-07-06 08:28:49 -040019#include "libANGLE/VertexArray.h"
Jamie Madill6df9b372015-02-18 21:28:19 +000020#include "libANGLE/features.h"
Jamie Madill54164b02017-08-28 15:17:37 -040021#include "libANGLE/queryconversions.h"
Jamie Madill8ecf7f92017-01-13 17:29:52 -050022#include "libANGLE/renderer/ContextImpl.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050023#include "libANGLE/renderer/d3d/DynamicHLSL.h"
Jamie Madill85a18042015-03-05 15:41:41 -050024#include "libANGLE/renderer/d3d/FramebufferD3D.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050025#include "libANGLE/renderer/d3d/RendererD3D.h"
26#include "libANGLE/renderer/d3d/ShaderD3D.h"
Geoff Lang359ef262015-01-05 14:42:29 -050027#include "libANGLE/renderer/d3d/ShaderExecutableD3D.h"
Jamie Madill437d2662014-12-05 14:23:35 -050028#include "libANGLE/renderer/d3d/VertexDataManager.h"
Geoff Lang22072132014-11-20 15:15:01 -050029
Jamie Madill01074252016-11-28 15:55:51 -050030using namespace angle;
31
Brandon Jonesc9610c52014-08-25 17:02:59 -070032namespace rx
33{
34
Brandon Joneseb994362014-09-24 10:27:28 -070035namespace
36{
37
Jamie Madill4c19a8a2017-07-24 11:46:06 -040038void GetDefaultInputLayoutFromShader(const gl::Context *context,
39 gl::Shader *vertexShader,
40 gl::InputLayout *inputLayoutOut)
Brandon Joneseb994362014-09-24 10:27:28 -070041{
Jamie Madill4c19a8a2017-07-24 11:46:06 -040042 inputLayoutOut->clear();
43
Jamie Madillbd044ed2017-06-05 12:59:21 -040044 for (const sh::Attribute &shaderAttr : vertexShader->getActiveAttributes(context))
Brandon Joneseb994362014-09-24 10:27:28 -070045 {
Brandon Joneseb994362014-09-24 10:27:28 -070046 if (shaderAttr.type != GL_NONE)
47 {
48 GLenum transposedType = gl::TransposeMatrixType(shaderAttr.type);
49
Jamie Madilld3dfda22015-07-06 08:28:49 -040050 for (size_t rowIndex = 0;
Jamie Madill334d6152015-10-22 14:00:28 -040051 static_cast<int>(rowIndex) < gl::VariableRowCount(transposedType); ++rowIndex)
Brandon Joneseb994362014-09-24 10:27:28 -070052 {
Jamie Madilld3dfda22015-07-06 08:28:49 -040053 GLenum componentType = gl::VariableComponentType(transposedType);
Jamie Madill334d6152015-10-22 14:00:28 -040054 GLuint components = static_cast<GLuint>(gl::VariableColumnCount(transposedType));
Jamie Madilld3dfda22015-07-06 08:28:49 -040055 bool pureInt = (componentType != GL_FLOAT);
Jamie Madill334d6152015-10-22 14:00:28 -040056 gl::VertexFormatType defaultType =
57 gl::GetVertexFormatType(componentType, GL_FALSE, components, pureInt);
Brandon Joneseb994362014-09-24 10:27:28 -070058
Jamie Madill4c19a8a2017-07-24 11:46:06 -040059 inputLayoutOut->push_back(defaultType);
Brandon Joneseb994362014-09-24 10:27:28 -070060 }
61 }
62 }
63}
64
Jamie Madill4c19a8a2017-07-24 11:46:06 -040065void GetDefaultOutputLayoutFromShader(
66 const std::vector<PixelShaderOutputVariable> &shaderOutputVars,
67 std::vector<GLenum> *outputLayoutOut)
Brandon Joneseb994362014-09-24 10:27:28 -070068{
Jamie Madill4c19a8a2017-07-24 11:46:06 -040069 outputLayoutOut->clear();
Brandon Joneseb994362014-09-24 10:27:28 -070070
Jamie Madillb4463142014-12-19 14:56:54 -050071 if (!shaderOutputVars.empty())
72 {
Jamie Madill4c19a8a2017-07-24 11:46:06 -040073 outputLayoutOut->push_back(GL_COLOR_ATTACHMENT0 +
74 static_cast<unsigned int>(shaderOutputVars[0].outputIndex));
Jamie Madillb4463142014-12-19 14:56:54 -050075 }
Jamie Madill4c19a8a2017-07-24 11:46:06 -040076}
Brandon Joneseb994362014-09-24 10:27:28 -070077
Jamie Madill4c19a8a2017-07-24 11:46:06 -040078void GetPixelOutputLayoutFromFramebuffer(const gl::Context *context,
79 const gl::Framebuffer *framebuffer,
80 std::vector<GLenum> *signature)
81{
82 signature->clear();
83
84 FramebufferD3D *fboD3D = GetImplAs<FramebufferD3D>(framebuffer);
85 const auto &colorbuffers = fboD3D->getColorAttachmentsForRender(context);
86
87 for (size_t colorAttachment = 0; colorAttachment < colorbuffers.size(); ++colorAttachment)
88 {
89 const gl::FramebufferAttachment *colorbuffer = colorbuffers[colorAttachment];
90
91 if (colorbuffer)
92 {
93 signature->push_back(colorbuffer->getBinding() == GL_BACK ? GL_COLOR_ATTACHMENT0
94 : colorbuffer->getBinding());
95 }
96 else
97 {
98 signature->push_back(GL_NONE);
99 }
100 }
Brandon Joneseb994362014-09-24 10:27:28 -0700101}
102
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700103bool IsRowMajorLayout(const sh::InterfaceBlockField &var)
104{
105 return var.isRowMajorLayout;
106}
107
108bool IsRowMajorLayout(const sh::ShaderVariable &var)
109{
110 return false;
111}
112
Jamie Madill62d31cb2015-09-11 13:25:51 -0400113template <typename VarT>
114void GetUniformBlockInfo(const std::vector<VarT> &fields,
115 const std::string &prefix,
116 sh::BlockLayoutEncoder *encoder,
117 bool inRowMajorLayout,
118 std::map<std::string, sh::BlockMemberInfo> *blockInfoOut)
119{
120 for (const VarT &field : fields)
121 {
122 const std::string &fieldName = (prefix.empty() ? field.name : prefix + "." + field.name);
123
124 if (field.isStruct())
125 {
126 bool rowMajorLayout = (inRowMajorLayout || IsRowMajorLayout(field));
127
128 for (unsigned int arrayElement = 0; arrayElement < field.elementCount(); arrayElement++)
129 {
130 encoder->enterAggregateType();
131
132 const std::string uniformElementName =
133 fieldName + (field.isArray() ? ArrayString(arrayElement) : "");
134 GetUniformBlockInfo(field.fields, uniformElementName, encoder, rowMajorLayout,
135 blockInfoOut);
136
137 encoder->exitAggregateType();
138 }
139 }
140 else
141 {
142 bool isRowMajorMatrix = (gl::IsMatrixType(field.type) && inRowMajorLayout);
143 (*blockInfoOut)[fieldName] =
144 encoder->encodeType(field.type, field.arraySize, isRowMajorMatrix);
145 }
146 }
147}
148
Corentin Wallezb58e9ba2016-12-15 14:07:56 -0800149template <typename T, int cols, int rows>
150bool TransposeExpandMatrix(T *target, const GLfloat *value)
Jamie Madill334d6152015-10-22 14:00:28 -0400151{
Corentin Wallezb58e9ba2016-12-15 14:07:56 -0800152 constexpr int targetWidth = 4;
153 constexpr int targetHeight = rows;
154 constexpr int srcWidth = rows;
155 constexpr int srcHeight = cols;
156
157 constexpr int copyWidth = std::min(targetHeight, srcWidth);
158 constexpr int copyHeight = std::min(targetWidth, srcHeight);
159
160 T staging[targetWidth * targetHeight] = {0};
Jamie Madill334d6152015-10-22 14:00:28 -0400161
162 for (int x = 0; x < copyWidth; x++)
163 {
164 for (int y = 0; y < copyHeight; y++)
165 {
Corentin Wallezb58e9ba2016-12-15 14:07:56 -0800166 staging[x * targetWidth + y] = static_cast<T>(value[y * srcWidth + x]);
Jamie Madill334d6152015-10-22 14:00:28 -0400167 }
168 }
169
Corentin Wallezb58e9ba2016-12-15 14:07:56 -0800170 if (memcmp(target, staging, targetWidth * targetHeight * sizeof(T)) == 0)
171 {
172 return false;
173 }
174
175 memcpy(target, staging, targetWidth * targetHeight * sizeof(T));
176 return true;
Jamie Madill334d6152015-10-22 14:00:28 -0400177}
178
Corentin Wallezb58e9ba2016-12-15 14:07:56 -0800179template <typename T, int cols, int rows>
180bool ExpandMatrix(T *target, const GLfloat *value)
Jamie Madill334d6152015-10-22 14:00:28 -0400181{
Corentin Wallezb58e9ba2016-12-15 14:07:56 -0800182 constexpr int targetWidth = 4;
183 constexpr int targetHeight = rows;
184 constexpr int srcWidth = cols;
185 constexpr int srcHeight = rows;
186
187 constexpr int copyWidth = std::min(targetWidth, srcWidth);
188 constexpr int copyHeight = std::min(targetHeight, srcHeight);
189
190 T staging[targetWidth * targetHeight] = {0};
Jamie Madill334d6152015-10-22 14:00:28 -0400191
192 for (int y = 0; y < copyHeight; y++)
193 {
194 for (int x = 0; x < copyWidth; x++)
195 {
Corentin Wallezb58e9ba2016-12-15 14:07:56 -0800196 staging[y * targetWidth + x] = static_cast<T>(value[y * srcWidth + x]);
Jamie Madill334d6152015-10-22 14:00:28 -0400197 }
198 }
199
Corentin Wallezb58e9ba2016-12-15 14:07:56 -0800200 if (memcmp(target, staging, targetWidth * targetHeight * sizeof(T)) == 0)
201 {
202 return false;
203 }
204
205 memcpy(target, staging, targetWidth * targetHeight * sizeof(T));
206 return true;
Jamie Madill334d6152015-10-22 14:00:28 -0400207}
208
Jamie Madill4e31ad52015-10-29 10:32:57 -0400209gl::PrimitiveType GetGeometryShaderTypeFromDrawMode(GLenum drawMode)
210{
211 switch (drawMode)
212 {
213 // Uses the point sprite geometry shader.
214 case GL_POINTS:
215 return gl::PRIMITIVE_POINTS;
216
217 // All line drawing uses the same geometry shader.
218 case GL_LINES:
219 case GL_LINE_STRIP:
220 case GL_LINE_LOOP:
221 return gl::PRIMITIVE_LINES;
222
223 // The triangle fan primitive is emulated with strips in D3D11.
224 case GL_TRIANGLES:
225 case GL_TRIANGLE_FAN:
226 return gl::PRIMITIVE_TRIANGLES;
227
228 // Special case for triangle strips.
229 case GL_TRIANGLE_STRIP:
230 return gl::PRIMITIVE_TRIANGLE_STRIP;
231
232 default:
233 UNREACHABLE();
234 return gl::PRIMITIVE_TYPE_MAX;
235 }
236}
237
Jamie Madill192745a2016-12-22 15:58:21 -0500238bool FindFlatInterpolationVarying(const std::vector<sh::Varying> &varyings)
239{
240 // Note: this assumes nested structs can only be packed with one interpolation.
241 for (const auto &varying : varyings)
242 {
243 if (varying.interpolation == sh::INTERPOLATION_FLAT)
244 {
245 return true;
246 }
247 }
248
249 return false;
250}
251
Jamie Madillbe5e2ec2017-08-31 13:28:28 -0400252// Helper method to de-tranpose a matrix uniform for an API query.
253void GetMatrixUniform(GLint columns, GLint rows, GLfloat *dataOut, const GLfloat *source)
254{
255 for (GLint col = 0; col < columns; ++col)
256 {
257 for (GLint row = 0; row < rows; ++row)
258 {
259 GLfloat *outptr = dataOut + ((col * rows) + row);
260 const GLfloat *inptr = source + ((row * 4) + col);
261 *outptr = *inptr;
262 }
263 }
264}
265
266template <typename NonFloatT>
267void GetMatrixUniform(GLint columns, GLint rows, NonFloatT *dataOut, const NonFloatT *source)
268{
269 UNREACHABLE();
270}
271
Jamie Madillada9ecc2015-08-17 12:53:37 -0400272} // anonymous namespace
273
Jamie Madill28afae52015-11-09 15:07:57 -0500274// D3DUniform Implementation
275
Jamie Madill62d31cb2015-09-11 13:25:51 -0400276D3DUniform::D3DUniform(GLenum typeIn,
277 const std::string &nameIn,
278 unsigned int arraySizeIn,
279 bool defaultBlock)
280 : type(typeIn),
281 name(nameIn),
282 arraySize(arraySizeIn),
Jamie Madillbe5e2ec2017-08-31 13:28:28 -0400283 vsData(nullptr),
284 psData(nullptr),
285 csData(nullptr),
Jamie Madill62d31cb2015-09-11 13:25:51 -0400286 vsRegisterIndex(GL_INVALID_INDEX),
Geoff Lang98c56da2015-09-15 15:45:34 -0400287 psRegisterIndex(GL_INVALID_INDEX),
Xinghua Caob1239382016-12-13 15:07:05 +0800288 csRegisterIndex(GL_INVALID_INDEX),
Jamie Madill62d31cb2015-09-11 13:25:51 -0400289 registerCount(0),
290 registerElement(0)
291{
292 // We use data storage for default block uniforms to cache values that are sent to D3D during
293 // rendering
294 // Uniform blocks/buffers are treated separately by the Renderer (ES3 path only)
295 if (defaultBlock)
296 {
Jamie Madillcc2ed612017-03-14 15:59:00 -0400297 // Use the row count as register count, will work for non-square matrices.
Jamie Madill62d31cb2015-09-11 13:25:51 -0400298 registerCount = gl::VariableRowCount(type) * elementCount();
299 }
300}
301
302D3DUniform::~D3DUniform()
303{
Jamie Madillbe5e2ec2017-08-31 13:28:28 -0400304}
305
306const uint8_t *D3DUniform::getDataPtrToElement(size_t elementIndex) const
307{
308 ASSERT((arraySize == 0 && elementIndex == 0) || (arraySize > 0 && elementIndex < arraySize));
309
310 if (isSampler())
311 {
312 return reinterpret_cast<const uint8_t *>(&mSamplerData[elementIndex]);
313 }
314
315 return firstNonNullData() +
316 (elementIndex > 0 ? (gl::VariableInternalSize(type) * elementIndex) : 0u);
Jamie Madill62d31cb2015-09-11 13:25:51 -0400317}
318
319bool D3DUniform::isSampler() const
320{
321 return gl::IsSamplerType(type);
322}
323
324bool D3DUniform::isReferencedByVertexShader() const
325{
326 return vsRegisterIndex != GL_INVALID_INDEX;
327}
328
329bool D3DUniform::isReferencedByFragmentShader() const
330{
331 return psRegisterIndex != GL_INVALID_INDEX;
332}
333
Xinghua Caob1239382016-12-13 15:07:05 +0800334bool D3DUniform::isReferencedByComputeShader() const
335{
336 return csRegisterIndex != GL_INVALID_INDEX;
337}
338
Jamie Madillbe5e2ec2017-08-31 13:28:28 -0400339const uint8_t *D3DUniform::firstNonNullData() const
340{
341 ASSERT(vsData || psData || csData || !mSamplerData.empty());
342
343 if (!mSamplerData.empty())
344 {
345 return reinterpret_cast<const uint8_t *>(mSamplerData.data());
346 }
347
348 return vsData ? vsData : (psData ? psData : csData);
349}
350
Jamie Madill28afae52015-11-09 15:07:57 -0500351// D3DVarying Implementation
352
Jamie Madill9fc36822015-11-18 13:08:07 -0500353D3DVarying::D3DVarying() : semanticIndex(0), componentCount(0), outputSlot(0)
Jamie Madill28afae52015-11-09 15:07:57 -0500354{
355}
356
Jamie Madill9fc36822015-11-18 13:08:07 -0500357D3DVarying::D3DVarying(const std::string &semanticNameIn,
358 unsigned int semanticIndexIn,
359 unsigned int componentCountIn,
360 unsigned int outputSlotIn)
361 : semanticName(semanticNameIn),
362 semanticIndex(semanticIndexIn),
363 componentCount(componentCountIn),
364 outputSlot(outputSlotIn)
Jamie Madill28afae52015-11-09 15:07:57 -0500365{
366}
367
Jamie Madille39a3f02015-11-17 20:42:15 -0500368// ProgramD3DMetadata Implementation
369
Jamie Madillc9bde922016-07-24 17:58:50 -0400370ProgramD3DMetadata::ProgramD3DMetadata(RendererD3D *renderer,
Jamie Madille39a3f02015-11-17 20:42:15 -0500371 const ShaderD3D *vertexShader,
372 const ShaderD3D *fragmentShader)
Jamie Madillc9bde922016-07-24 17:58:50 -0400373 : mRendererMajorShaderModel(renderer->getMajorShaderModel()),
374 mShaderModelSuffix(renderer->getShaderModelSuffix()),
375 mUsesInstancedPointSpriteEmulation(
376 renderer->getWorkarounds().useInstancedPointSpriteEmulation),
377 mUsesViewScale(renderer->presentPathFastEnabled()),
Martin Radev41ac68e2017-06-06 12:16:58 +0300378 mHasANGLEMultiviewEnabled(vertexShader->hasANGLEMultiviewEnabled()),
379 mUsesViewID(fragmentShader->usesViewID()),
Jamie Madille39a3f02015-11-17 20:42:15 -0500380 mVertexShader(vertexShader),
381 mFragmentShader(fragmentShader)
382{
383}
384
385int ProgramD3DMetadata::getRendererMajorShaderModel() const
386{
387 return mRendererMajorShaderModel;
388}
389
Jamie Madill9082b982016-04-27 15:21:51 -0400390bool ProgramD3DMetadata::usesBroadcast(const gl::ContextState &data) const
Jamie Madille39a3f02015-11-17 20:42:15 -0500391{
Corentin Wallezc084de12017-06-05 14:28:52 -0700392 return (mFragmentShader->usesFragColor() && mFragmentShader->usesMultipleRenderTargets() &&
393 data.getClientMajorVersion() < 3);
Jamie Madille39a3f02015-11-17 20:42:15 -0500394}
395
Jamie Madill48ef11b2016-04-27 15:21:52 -0400396bool ProgramD3DMetadata::usesFragDepth() const
Jamie Madille39a3f02015-11-17 20:42:15 -0500397{
Jamie Madill63286672015-11-24 13:00:08 -0500398 return mFragmentShader->usesFragDepth();
Jamie Madille39a3f02015-11-17 20:42:15 -0500399}
400
401bool ProgramD3DMetadata::usesPointCoord() const
402{
403 return mFragmentShader->usesPointCoord();
404}
405
406bool ProgramD3DMetadata::usesFragCoord() const
407{
408 return mFragmentShader->usesFragCoord();
409}
410
411bool ProgramD3DMetadata::usesPointSize() const
412{
413 return mVertexShader->usesPointSize();
414}
415
416bool ProgramD3DMetadata::usesInsertedPointCoordValue() const
417{
Jamie Madillc9bde922016-07-24 17:58:50 -0400418 return (!usesPointSize() || !mUsesInstancedPointSpriteEmulation) && usesPointCoord() &&
419 mRendererMajorShaderModel >= 4;
Jamie Madille39a3f02015-11-17 20:42:15 -0500420}
421
Austin Kinross2a63b3f2016-02-08 12:29:08 -0800422bool ProgramD3DMetadata::usesViewScale() const
423{
424 return mUsesViewScale;
425}
426
Martin Radev41ac68e2017-06-06 12:16:58 +0300427bool ProgramD3DMetadata::hasANGLEMultiviewEnabled() const
428{
429 return mHasANGLEMultiviewEnabled;
430}
431
432bool ProgramD3DMetadata::usesViewID() const
433{
434 return mUsesViewID;
435}
436
Jamie Madille39a3f02015-11-17 20:42:15 -0500437bool ProgramD3DMetadata::addsPointCoordToVertexShader() const
438{
Jamie Madillc9bde922016-07-24 17:58:50 -0400439 // PointSprite emulation requiress that gl_PointCoord is present in the vertex shader
Jamie Madille39a3f02015-11-17 20:42:15 -0500440 // VS_OUTPUT structure to ensure compatibility with the generated PS_INPUT of the pixel shader.
Jamie Madillc9bde922016-07-24 17:58:50 -0400441 // Even with a geometry shader, the app can render triangles or lines and reference
442 // gl_PointCoord in the fragment shader, requiring us to provide a dummy value. For
443 // simplicity, we always add this to the vertex shader when the fragment shader
444 // references gl_PointCoord, even if we could skip it in the geometry shader.
Jamie Madille39a3f02015-11-17 20:42:15 -0500445 return (mUsesInstancedPointSpriteEmulation && usesPointCoord()) ||
446 usesInsertedPointCoordValue();
447}
448
449bool ProgramD3DMetadata::usesTransformFeedbackGLPosition() const
450{
451 // gl_Position only needs to be outputted from the vertex shader if transform feedback is
452 // active. This isn't supported on D3D11 Feature Level 9_3, so we don't output gl_Position from
453 // the vertex shader in this case. This saves us 1 output vector.
454 return !(mRendererMajorShaderModel >= 4 && mShaderModelSuffix != "");
455}
456
457bool ProgramD3DMetadata::usesSystemValuePointSize() const
458{
459 return !mUsesInstancedPointSpriteEmulation && usesPointSize();
460}
461
462bool ProgramD3DMetadata::usesMultipleFragmentOuts() const
463{
464 return mFragmentShader->usesMultipleRenderTargets();
465}
466
467GLint ProgramD3DMetadata::getMajorShaderVersion() const
468{
469 return mVertexShader->getData().getShaderVersion();
470}
471
472const ShaderD3D *ProgramD3DMetadata::getFragmentShader() const
473{
474 return mFragmentShader;
475}
476
Jamie Madill28afae52015-11-09 15:07:57 -0500477// ProgramD3D Implementation
478
Jamie Madilld3dfda22015-07-06 08:28:49 -0400479ProgramD3D::VertexExecutable::VertexExecutable(const gl::InputLayout &inputLayout,
480 const Signature &signature,
Geoff Lang359ef262015-01-05 14:42:29 -0500481 ShaderExecutableD3D *shaderExecutable)
Jamie Madill334d6152015-10-22 14:00:28 -0400482 : mInputs(inputLayout), mSignature(signature), mShaderExecutable(shaderExecutable)
Brandon Joneseb994362014-09-24 10:27:28 -0700483{
Brandon Joneseb994362014-09-24 10:27:28 -0700484}
485
486ProgramD3D::VertexExecutable::~VertexExecutable()
487{
488 SafeDelete(mShaderExecutable);
489}
490
Jamie Madilld3dfda22015-07-06 08:28:49 -0400491// static
Jamie Madillbdec2f42016-03-02 16:35:32 -0500492ProgramD3D::VertexExecutable::HLSLAttribType ProgramD3D::VertexExecutable::GetAttribType(
493 GLenum type)
494{
495 switch (type)
496 {
497 case GL_INT:
498 return HLSLAttribType::SIGNED_INT;
499 case GL_UNSIGNED_INT:
500 return HLSLAttribType::UNSIGNED_INT;
501 case GL_SIGNED_NORMALIZED:
502 case GL_UNSIGNED_NORMALIZED:
503 case GL_FLOAT:
504 return HLSLAttribType::FLOAT;
505 default:
506 UNREACHABLE();
507 return HLSLAttribType::FLOAT;
508 }
509}
510
511// static
Jamie Madilld3dfda22015-07-06 08:28:49 -0400512void ProgramD3D::VertexExecutable::getSignature(RendererD3D *renderer,
513 const gl::InputLayout &inputLayout,
514 Signature *signatureOut)
Brandon Joneseb994362014-09-24 10:27:28 -0700515{
Jamie Madillbdec2f42016-03-02 16:35:32 -0500516 signatureOut->assign(inputLayout.size(), HLSLAttribType::FLOAT);
Jamie Madilld3dfda22015-07-06 08:28:49 -0400517
518 for (size_t index = 0; index < inputLayout.size(); ++index)
Brandon Joneseb994362014-09-24 10:27:28 -0700519 {
Jamie Madilld3dfda22015-07-06 08:28:49 -0400520 gl::VertexFormatType vertexFormatType = inputLayout[index];
Jamie Madillbdec2f42016-03-02 16:35:32 -0500521 if (vertexFormatType == gl::VERTEX_FORMAT_INVALID)
522 continue;
Jamie Madillbd136f92015-08-10 14:51:37 -0400523
Jamie Madillbdec2f42016-03-02 16:35:32 -0500524 VertexConversionType conversionType = renderer->getVertexConversionType(vertexFormatType);
525 if ((conversionType & VERTEX_CONVERT_GPU) == 0)
526 continue;
527
528 GLenum componentType = renderer->getVertexComponentType(vertexFormatType);
529 (*signatureOut)[index] = GetAttribType(componentType);
Brandon Joneseb994362014-09-24 10:27:28 -0700530 }
Brandon Joneseb994362014-09-24 10:27:28 -0700531}
532
Jamie Madilld3dfda22015-07-06 08:28:49 -0400533bool ProgramD3D::VertexExecutable::matchesSignature(const Signature &signature) const
534{
Jamie Madillbd136f92015-08-10 14:51:37 -0400535 size_t limit = std::max(mSignature.size(), signature.size());
536 for (size_t index = 0; index < limit; ++index)
537 {
Jamie Madillbdec2f42016-03-02 16:35:32 -0500538 // treat undefined indexes as FLOAT
539 auto a = index < signature.size() ? signature[index] : HLSLAttribType::FLOAT;
540 auto b = index < mSignature.size() ? mSignature[index] : HLSLAttribType::FLOAT;
Jamie Madillbd136f92015-08-10 14:51:37 -0400541 if (a != b)
542 return false;
543 }
544
545 return true;
Jamie Madilld3dfda22015-07-06 08:28:49 -0400546}
547
548ProgramD3D::PixelExecutable::PixelExecutable(const std::vector<GLenum> &outputSignature,
549 ShaderExecutableD3D *shaderExecutable)
Jamie Madill334d6152015-10-22 14:00:28 -0400550 : mOutputSignature(outputSignature), mShaderExecutable(shaderExecutable)
Brandon Joneseb994362014-09-24 10:27:28 -0700551{
552}
553
554ProgramD3D::PixelExecutable::~PixelExecutable()
555{
556 SafeDelete(mShaderExecutable);
557}
558
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700559ProgramD3D::Sampler::Sampler() : active(false), logicalTextureUnit(0), textureType(GL_TEXTURE_2D)
560{
561}
562
Geoff Lang7dd2e102014-11-10 15:19:26 -0500563unsigned int ProgramD3D::mCurrentSerial = 1;
564
Jamie Madill48ef11b2016-04-27 15:21:52 -0400565ProgramD3D::ProgramD3D(const gl::ProgramState &state, RendererD3D *renderer)
566 : ProgramImpl(state),
Brandon Jonesc9610c52014-08-25 17:02:59 -0700567 mRenderer(renderer),
Xinghua Caob1239382016-12-13 15:07:05 +0800568 mDynamicHLSL(nullptr),
569 mGeometryExecutables(gl::PRIMITIVE_TYPE_MAX),
570 mComputeExecutable(nullptr),
Brandon Jones44151a92014-09-10 11:32:25 -0700571 mUsesPointSize(false),
Jamie Madill3e14e2b2015-10-29 14:38:53 -0400572 mUsesFlatInterpolation(false),
Xinghua Caob1239382016-12-13 15:07:05 +0800573 mVertexUniformStorage(nullptr),
574 mFragmentUniformStorage(nullptr),
575 mComputeUniformStorage(nullptr),
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700576 mUsedVertexSamplerRange(0),
577 mUsedPixelSamplerRange(0),
Xinghua Caob1239382016-12-13 15:07:05 +0800578 mUsedComputeSamplerRange(0),
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700579 mDirtySamplerMapping(true),
Jamie Madill561ed3a2017-08-31 16:48:09 -0400580 mSerial(issueSerial()),
581 mUniformsDirty(true)
Brandon Jonesc9610c52014-08-25 17:02:59 -0700582{
Brandon Joneseb994362014-09-24 10:27:28 -0700583 mDynamicHLSL = new DynamicHLSL(renderer);
Brandon Jonesc9610c52014-08-25 17:02:59 -0700584}
585
586ProgramD3D::~ProgramD3D()
587{
588 reset();
589 SafeDelete(mDynamicHLSL);
590}
591
Brandon Jones44151a92014-09-10 11:32:25 -0700592bool ProgramD3D::usesPointSpriteEmulation() const
593{
594 return mUsesPointSize && mRenderer->getMajorShaderModel() >= 4;
595}
596
Martin Radev41ac68e2017-06-06 12:16:58 +0300597bool ProgramD3D::usesGeometryShaderForPointSpriteEmulation() const
598{
599 return usesPointSpriteEmulation() && !usesInstancedPointSpriteEmulation();
600}
601
Jamie Madill3e14e2b2015-10-29 14:38:53 -0400602bool ProgramD3D::usesGeometryShader(GLenum drawMode) const
Brandon Jones44151a92014-09-10 11:32:25 -0700603{
Martin Radev41ac68e2017-06-06 12:16:58 +0300604 if (mHasANGLEMultiviewEnabled)
605 {
606 return true;
607 }
Jamie Madill3e14e2b2015-10-29 14:38:53 -0400608 if (drawMode != GL_POINTS)
609 {
610 return mUsesFlatInterpolation;
611 }
Martin Radev41ac68e2017-06-06 12:16:58 +0300612 return usesGeometryShaderForPointSpriteEmulation();
Cooper Partine6664f02015-01-09 16:22:24 -0800613}
614
615bool ProgramD3D::usesInstancedPointSpriteEmulation() const
616{
617 return mRenderer->getWorkarounds().useInstancedPointSpriteEmulation;
Brandon Jones44151a92014-09-10 11:32:25 -0700618}
619
Jamie Madill334d6152015-10-22 14:00:28 -0400620GLint ProgramD3D::getSamplerMapping(gl::SamplerType type,
621 unsigned int samplerIndex,
622 const gl::Caps &caps) const
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700623{
624 GLint logicalTextureUnit = -1;
625
626 switch (type)
627 {
Jamie Madill334d6152015-10-22 14:00:28 -0400628 case gl::SAMPLER_PIXEL:
629 ASSERT(samplerIndex < caps.maxTextureImageUnits);
630 if (samplerIndex < mSamplersPS.size() && mSamplersPS[samplerIndex].active)
631 {
632 logicalTextureUnit = mSamplersPS[samplerIndex].logicalTextureUnit;
633 }
634 break;
635 case gl::SAMPLER_VERTEX:
636 ASSERT(samplerIndex < caps.maxVertexTextureImageUnits);
637 if (samplerIndex < mSamplersVS.size() && mSamplersVS[samplerIndex].active)
638 {
639 logicalTextureUnit = mSamplersVS[samplerIndex].logicalTextureUnit;
640 }
641 break;
Xinghua Caob1239382016-12-13 15:07:05 +0800642 case gl::SAMPLER_COMPUTE:
643 ASSERT(samplerIndex < caps.maxComputeTextureImageUnits);
644 if (samplerIndex < mSamplersCS.size() && mSamplersCS[samplerIndex].active)
645 {
646 logicalTextureUnit = mSamplersCS[samplerIndex].logicalTextureUnit;
647 }
648 break;
Jamie Madill334d6152015-10-22 14:00:28 -0400649 default:
650 UNREACHABLE();
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700651 }
652
Jamie Madill334d6152015-10-22 14:00:28 -0400653 if (logicalTextureUnit >= 0 &&
654 logicalTextureUnit < static_cast<GLint>(caps.maxCombinedTextureImageUnits))
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700655 {
656 return logicalTextureUnit;
657 }
658
659 return -1;
660}
661
662// Returns the texture type for a given Direct3D 9 sampler type and
663// index (0-15 for the pixel shader and 0-3 for the vertex shader).
664GLenum ProgramD3D::getSamplerTextureType(gl::SamplerType type, unsigned int samplerIndex) const
665{
666 switch (type)
667 {
Jamie Madill334d6152015-10-22 14:00:28 -0400668 case gl::SAMPLER_PIXEL:
669 ASSERT(samplerIndex < mSamplersPS.size());
670 ASSERT(mSamplersPS[samplerIndex].active);
671 return mSamplersPS[samplerIndex].textureType;
672 case gl::SAMPLER_VERTEX:
673 ASSERT(samplerIndex < mSamplersVS.size());
674 ASSERT(mSamplersVS[samplerIndex].active);
675 return mSamplersVS[samplerIndex].textureType;
Xinghua Caob1239382016-12-13 15:07:05 +0800676 case gl::SAMPLER_COMPUTE:
677 ASSERT(samplerIndex < mSamplersCS.size());
678 ASSERT(mSamplersCS[samplerIndex].active);
679 return mSamplersCS[samplerIndex].textureType;
Jamie Madill334d6152015-10-22 14:00:28 -0400680 default:
681 UNREACHABLE();
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700682 }
683
684 return GL_TEXTURE_2D;
685}
686
Olli Etuaho618bebc2016-01-15 16:40:00 +0200687GLuint ProgramD3D::getUsedSamplerRange(gl::SamplerType type) const
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700688{
689 switch (type)
690 {
Jamie Madill334d6152015-10-22 14:00:28 -0400691 case gl::SAMPLER_PIXEL:
692 return mUsedPixelSamplerRange;
693 case gl::SAMPLER_VERTEX:
694 return mUsedVertexSamplerRange;
Xinghua Caob1239382016-12-13 15:07:05 +0800695 case gl::SAMPLER_COMPUTE:
696 return mUsedComputeSamplerRange;
Jamie Madill334d6152015-10-22 14:00:28 -0400697 default:
698 UNREACHABLE();
Olli Etuaho618bebc2016-01-15 16:40:00 +0200699 return 0u;
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700700 }
701}
702
703void ProgramD3D::updateSamplerMapping()
704{
705 if (!mDirtySamplerMapping)
706 {
707 return;
708 }
709
710 mDirtySamplerMapping = false;
711
712 // Retrieve sampler uniform values
Jamie Madill62d31cb2015-09-11 13:25:51 -0400713 for (const D3DUniform *d3dUniform : mD3DUniforms)
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700714 {
Jamie Madill62d31cb2015-09-11 13:25:51 -0400715 if (!d3dUniform->isSampler())
716 continue;
717
718 int count = d3dUniform->elementCount();
Jamie Madill62d31cb2015-09-11 13:25:51 -0400719
720 if (d3dUniform->isReferencedByFragmentShader())
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700721 {
Jamie Madill62d31cb2015-09-11 13:25:51 -0400722 unsigned int firstIndex = d3dUniform->psRegisterIndex;
723
724 for (int i = 0; i < count; i++)
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700725 {
Jamie Madill62d31cb2015-09-11 13:25:51 -0400726 unsigned int samplerIndex = firstIndex + i;
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700727
Jamie Madill62d31cb2015-09-11 13:25:51 -0400728 if (samplerIndex < mSamplersPS.size())
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700729 {
Jamie Madill62d31cb2015-09-11 13:25:51 -0400730 ASSERT(mSamplersPS[samplerIndex].active);
Jamie Madillbe5e2ec2017-08-31 13:28:28 -0400731 mSamplersPS[samplerIndex].logicalTextureUnit = d3dUniform->mSamplerData[i];
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700732 }
Jamie Madill62d31cb2015-09-11 13:25:51 -0400733 }
734 }
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700735
Jamie Madill62d31cb2015-09-11 13:25:51 -0400736 if (d3dUniform->isReferencedByVertexShader())
737 {
738 unsigned int firstIndex = d3dUniform->vsRegisterIndex;
739
740 for (int i = 0; i < count; i++)
741 {
742 unsigned int samplerIndex = firstIndex + i;
743
744 if (samplerIndex < mSamplersVS.size())
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700745 {
Jamie Madill62d31cb2015-09-11 13:25:51 -0400746 ASSERT(mSamplersVS[samplerIndex].active);
Jamie Madillbe5e2ec2017-08-31 13:28:28 -0400747 mSamplersVS[samplerIndex].logicalTextureUnit = d3dUniform->mSamplerData[i];
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700748 }
749 }
750 }
Xinghua Caob1239382016-12-13 15:07:05 +0800751
752 if (d3dUniform->isReferencedByComputeShader())
753 {
754 unsigned int firstIndex = d3dUniform->csRegisterIndex;
755
756 for (int i = 0; i < count; i++)
757 {
758 unsigned int samplerIndex = firstIndex + i;
759
760 if (samplerIndex < mSamplersCS.size())
761 {
762 ASSERT(mSamplersCS[samplerIndex].active);
Jamie Madillbe5e2ec2017-08-31 13:28:28 -0400763 mSamplersCS[samplerIndex].logicalTextureUnit = d3dUniform->mSamplerData[i];
Xinghua Caob1239382016-12-13 15:07:05 +0800764 }
765 }
766 }
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700767 }
768}
769
Jamie Madill9cf9e872017-06-05 12:59:25 -0400770gl::LinkResult ProgramD3D::load(const gl::Context *context,
771 gl::InfoLog &infoLog,
772 gl::BinaryInputStream *stream)
Brandon Jones22502d52014-08-29 16:58:36 -0700773{
Jamie Madilla7d12dc2016-12-13 15:08:19 -0500774 // TODO(jmadill): Use Renderer from contextImpl.
775
Jamie Madill62d31cb2015-09-11 13:25:51 -0400776 reset();
777
Jamie Madill334d6152015-10-22 14:00:28 -0400778 DeviceIdentifier binaryDeviceIdentifier = {0};
779 stream->readBytes(reinterpret_cast<unsigned char *>(&binaryDeviceIdentifier),
780 sizeof(DeviceIdentifier));
Austin Kinross137b1512015-06-17 16:14:53 -0700781
782 DeviceIdentifier identifier = mRenderer->getAdapterIdentifier();
783 if (memcmp(&identifier, &binaryDeviceIdentifier, sizeof(DeviceIdentifier)) != 0)
784 {
785 infoLog << "Invalid program binary, device configuration has changed.";
Jamie Madillb0a838b2016-11-13 20:02:12 -0500786 return false;
Austin Kinross137b1512015-06-17 16:14:53 -0700787 }
788
Jamie Madill2db1fbb2014-12-03 10:58:55 -0500789 int compileFlags = stream->readInt<int>();
790 if (compileFlags != ANGLE_COMPILE_OPTIMIZATION_LEVEL)
791 {
Jamie Madillf6113162015-05-07 11:49:21 -0400792 infoLog << "Mismatched compilation flags.";
Jamie Madillb0a838b2016-11-13 20:02:12 -0500793 return false;
Jamie Madill2db1fbb2014-12-03 10:58:55 -0500794 }
795
Jamie Madill8047c0d2016-03-07 13:02:12 -0500796 for (int &index : mAttribLocationToD3DSemantic)
Jamie Madill63805b42015-08-25 13:17:39 -0400797 {
Jamie Madill8047c0d2016-03-07 13:02:12 -0500798 stream->readInt(&index);
Jamie Madill63805b42015-08-25 13:17:39 -0400799 }
800
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700801 const unsigned int psSamplerCount = stream->readInt<unsigned int>();
802 for (unsigned int i = 0; i < psSamplerCount; ++i)
803 {
804 Sampler sampler;
805 stream->readBool(&sampler.active);
806 stream->readInt(&sampler.logicalTextureUnit);
807 stream->readInt(&sampler.textureType);
808 mSamplersPS.push_back(sampler);
809 }
810 const unsigned int vsSamplerCount = stream->readInt<unsigned int>();
811 for (unsigned int i = 0; i < vsSamplerCount; ++i)
812 {
813 Sampler sampler;
814 stream->readBool(&sampler.active);
815 stream->readInt(&sampler.logicalTextureUnit);
816 stream->readInt(&sampler.textureType);
817 mSamplersVS.push_back(sampler);
818 }
819
Xinghua Caob1239382016-12-13 15:07:05 +0800820 const unsigned int csSamplerCount = stream->readInt<unsigned int>();
821 for (unsigned int i = 0; i < csSamplerCount; ++i)
822 {
823 Sampler sampler;
824 stream->readBool(&sampler.active);
825 stream->readInt(&sampler.logicalTextureUnit);
826 stream->readInt(&sampler.textureType);
827 mSamplersCS.push_back(sampler);
828 }
829
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700830 stream->readInt(&mUsedVertexSamplerRange);
831 stream->readInt(&mUsedPixelSamplerRange);
Xinghua Caob1239382016-12-13 15:07:05 +0800832 stream->readInt(&mUsedComputeSamplerRange);
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700833
834 const unsigned int uniformCount = stream->readInt<unsigned int>();
835 if (stream->error())
836 {
Jamie Madillf6113162015-05-07 11:49:21 -0400837 infoLog << "Invalid program binary.";
Jamie Madillb0a838b2016-11-13 20:02:12 -0500838 return false;
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700839 }
840
Jamie Madill48ef11b2016-04-27 15:21:52 -0400841 const auto &linkedUniforms = mState.getUniforms();
Jamie Madill62d31cb2015-09-11 13:25:51 -0400842 ASSERT(mD3DUniforms.empty());
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700843 for (unsigned int uniformIndex = 0; uniformIndex < uniformCount; uniformIndex++)
844 {
Jamie Madill62d31cb2015-09-11 13:25:51 -0400845 const gl::LinkedUniform &linkedUniform = linkedUniforms[uniformIndex];
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700846
Jamie Madill62d31cb2015-09-11 13:25:51 -0400847 D3DUniform *d3dUniform =
848 new D3DUniform(linkedUniform.type, linkedUniform.name, linkedUniform.arraySize,
849 linkedUniform.isInDefaultBlock());
850 stream->readInt(&d3dUniform->psRegisterIndex);
851 stream->readInt(&d3dUniform->vsRegisterIndex);
Xinghua Caob1239382016-12-13 15:07:05 +0800852 stream->readInt(&d3dUniform->csRegisterIndex);
Jamie Madill62d31cb2015-09-11 13:25:51 -0400853 stream->readInt(&d3dUniform->registerCount);
854 stream->readInt(&d3dUniform->registerElement);
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700855
Jamie Madill62d31cb2015-09-11 13:25:51 -0400856 mD3DUniforms.push_back(d3dUniform);
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700857 }
858
Jamie Madill4a3c2342015-10-08 12:58:45 -0400859 const unsigned int blockCount = stream->readInt<unsigned int>();
860 if (stream->error())
861 {
862 infoLog << "Invalid program binary.";
Jamie Madillb0a838b2016-11-13 20:02:12 -0500863 return false;
Jamie Madill4a3c2342015-10-08 12:58:45 -0400864 }
865
866 ASSERT(mD3DUniformBlocks.empty());
867 for (unsigned int blockIndex = 0; blockIndex < blockCount; ++blockIndex)
868 {
869 D3DUniformBlock uniformBlock;
870 stream->readInt(&uniformBlock.psRegisterIndex);
871 stream->readInt(&uniformBlock.vsRegisterIndex);
Xinghua Caob1239382016-12-13 15:07:05 +0800872 stream->readInt(&uniformBlock.csRegisterIndex);
Jamie Madill4a3c2342015-10-08 12:58:45 -0400873 mD3DUniformBlocks.push_back(uniformBlock);
874 }
875
Jamie Madill9fc36822015-11-18 13:08:07 -0500876 const unsigned int streamOutVaryingCount = stream->readInt<unsigned int>();
877 mStreamOutVaryings.resize(streamOutVaryingCount);
878 for (unsigned int varyingIndex = 0; varyingIndex < streamOutVaryingCount; ++varyingIndex)
Brandon Joneseb994362014-09-24 10:27:28 -0700879 {
Jamie Madill9fc36822015-11-18 13:08:07 -0500880 D3DVarying *varying = &mStreamOutVaryings[varyingIndex];
Brandon Joneseb994362014-09-24 10:27:28 -0700881
Jamie Madill28afae52015-11-09 15:07:57 -0500882 stream->readString(&varying->semanticName);
883 stream->readInt(&varying->semanticIndex);
Jamie Madill9fc36822015-11-18 13:08:07 -0500884 stream->readInt(&varying->componentCount);
885 stream->readInt(&varying->outputSlot);
Brandon Joneseb994362014-09-24 10:27:28 -0700886 }
887
Brandon Jones22502d52014-08-29 16:58:36 -0700888 stream->readString(&mVertexHLSL);
Jamie Madill334d6152015-10-22 14:00:28 -0400889 stream->readBytes(reinterpret_cast<unsigned char *>(&mVertexWorkarounds),
Jamie Madill408293f2016-12-20 10:11:45 -0500890 sizeof(angle::CompilerWorkaroundsD3D));
Brandon Jones22502d52014-08-29 16:58:36 -0700891 stream->readString(&mPixelHLSL);
Jamie Madill334d6152015-10-22 14:00:28 -0400892 stream->readBytes(reinterpret_cast<unsigned char *>(&mPixelWorkarounds),
Jamie Madill408293f2016-12-20 10:11:45 -0500893 sizeof(angle::CompilerWorkaroundsD3D));
Brandon Jones22502d52014-08-29 16:58:36 -0700894 stream->readBool(&mUsesFragDepth);
Martin Radev41ac68e2017-06-06 12:16:58 +0300895 stream->readBool(&mHasANGLEMultiviewEnabled);
896 stream->readBool(&mUsesViewID);
Brandon Jones44151a92014-09-10 11:32:25 -0700897 stream->readBool(&mUsesPointSize);
Jamie Madill3e14e2b2015-10-29 14:38:53 -0400898 stream->readBool(&mUsesFlatInterpolation);
Brandon Jones22502d52014-08-29 16:58:36 -0700899
900 const size_t pixelShaderKeySize = stream->readInt<unsigned int>();
901 mPixelShaderKey.resize(pixelShaderKeySize);
Jamie Madill334d6152015-10-22 14:00:28 -0400902 for (size_t pixelShaderKeyIndex = 0; pixelShaderKeyIndex < pixelShaderKeySize;
903 pixelShaderKeyIndex++)
Brandon Jones22502d52014-08-29 16:58:36 -0700904 {
905 stream->readInt(&mPixelShaderKey[pixelShaderKeyIndex].type);
906 stream->readString(&mPixelShaderKey[pixelShaderKeyIndex].name);
907 stream->readString(&mPixelShaderKey[pixelShaderKeyIndex].source);
908 stream->readInt(&mPixelShaderKey[pixelShaderKeyIndex].outputIndex);
909 }
910
Jamie Madill4e31ad52015-10-29 10:32:57 -0400911 stream->readString(&mGeometryShaderPreamble);
912
Jamie Madill334d6152015-10-22 14:00:28 -0400913 const unsigned char *binary = reinterpret_cast<const unsigned char *>(stream->data());
Brandon Joneseb994362014-09-24 10:27:28 -0700914
Jamie Madillb0a838b2016-11-13 20:02:12 -0500915 bool separateAttribs = (mState.getTransformFeedbackBufferMode() == GL_SEPARATE_ATTRIBS);
916
Brandon Joneseb994362014-09-24 10:27:28 -0700917 const unsigned int vertexShaderCount = stream->readInt<unsigned int>();
Jamie Madill334d6152015-10-22 14:00:28 -0400918 for (unsigned int vertexShaderIndex = 0; vertexShaderIndex < vertexShaderCount;
919 vertexShaderIndex++)
Brandon Joneseb994362014-09-24 10:27:28 -0700920 {
Jamie Madilld3dfda22015-07-06 08:28:49 -0400921 size_t inputLayoutSize = stream->readInt<size_t>();
Jamie Madillf8dd7b12015-08-05 13:50:08 -0400922 gl::InputLayout inputLayout(inputLayoutSize, gl::VERTEX_FORMAT_INVALID);
Brandon Joneseb994362014-09-24 10:27:28 -0700923
Jamie Madilld3dfda22015-07-06 08:28:49 -0400924 for (size_t inputIndex = 0; inputIndex < inputLayoutSize; inputIndex++)
Brandon Joneseb994362014-09-24 10:27:28 -0700925 {
Jamie Madillf8dd7b12015-08-05 13:50:08 -0400926 inputLayout[inputIndex] = stream->readInt<gl::VertexFormatType>();
Brandon Joneseb994362014-09-24 10:27:28 -0700927 }
928
Jamie Madill334d6152015-10-22 14:00:28 -0400929 unsigned int vertexShaderSize = stream->readInt<unsigned int>();
Brandon Joneseb994362014-09-24 10:27:28 -0700930 const unsigned char *vertexShaderFunction = binary + stream->offset();
Geoff Langb543aff2014-09-30 14:52:54 -0400931
Jamie Madillada9ecc2015-08-17 12:53:37 -0400932 ShaderExecutableD3D *shaderExecutable = nullptr;
933
Jamie Madillb0a838b2016-11-13 20:02:12 -0500934 ANGLE_TRY(mRenderer->loadExecutable(vertexShaderFunction, vertexShaderSize, SHADER_VERTEX,
935 mStreamOutVaryings, separateAttribs,
936 &shaderExecutable));
Geoff Langb543aff2014-09-30 14:52:54 -0400937
Brandon Joneseb994362014-09-24 10:27:28 -0700938 if (!shaderExecutable)
939 {
Jamie Madillf6113162015-05-07 11:49:21 -0400940 infoLog << "Could not create vertex shader.";
Jamie Madillb0a838b2016-11-13 20:02:12 -0500941 return false;
Brandon Joneseb994362014-09-24 10:27:28 -0700942 }
943
944 // generated converted input layout
Jamie Madilld3dfda22015-07-06 08:28:49 -0400945 VertexExecutable::Signature signature;
946 VertexExecutable::getSignature(mRenderer, inputLayout, &signature);
Brandon Joneseb994362014-09-24 10:27:28 -0700947
948 // add new binary
Xinghua Caob1239382016-12-13 15:07:05 +0800949 mVertexExecutables.push_back(std::unique_ptr<VertexExecutable>(
950 new VertexExecutable(inputLayout, signature, shaderExecutable)));
Brandon Joneseb994362014-09-24 10:27:28 -0700951
952 stream->skip(vertexShaderSize);
953 }
954
955 const size_t pixelShaderCount = stream->readInt<unsigned int>();
956 for (size_t pixelShaderIndex = 0; pixelShaderIndex < pixelShaderCount; pixelShaderIndex++)
957 {
958 const size_t outputCount = stream->readInt<unsigned int>();
959 std::vector<GLenum> outputs(outputCount);
960 for (size_t outputIndex = 0; outputIndex < outputCount; outputIndex++)
961 {
962 stream->readInt(&outputs[outputIndex]);
963 }
964
Jamie Madill334d6152015-10-22 14:00:28 -0400965 const size_t pixelShaderSize = stream->readInt<unsigned int>();
Brandon Joneseb994362014-09-24 10:27:28 -0700966 const unsigned char *pixelShaderFunction = binary + stream->offset();
Jamie Madillada9ecc2015-08-17 12:53:37 -0400967 ShaderExecutableD3D *shaderExecutable = nullptr;
968
Jamie Madillb0a838b2016-11-13 20:02:12 -0500969 ANGLE_TRY(mRenderer->loadExecutable(pixelShaderFunction, pixelShaderSize, SHADER_PIXEL,
970 mStreamOutVaryings, separateAttribs,
971 &shaderExecutable));
Brandon Joneseb994362014-09-24 10:27:28 -0700972
973 if (!shaderExecutable)
974 {
Jamie Madillf6113162015-05-07 11:49:21 -0400975 infoLog << "Could not create pixel shader.";
Jamie Madillb0a838b2016-11-13 20:02:12 -0500976 return false;
Brandon Joneseb994362014-09-24 10:27:28 -0700977 }
978
979 // add new binary
Xinghua Caob1239382016-12-13 15:07:05 +0800980 mPixelExecutables.push_back(
981 std::unique_ptr<PixelExecutable>(new PixelExecutable(outputs, shaderExecutable)));
Brandon Joneseb994362014-09-24 10:27:28 -0700982
983 stream->skip(pixelShaderSize);
984 }
985
Jamie Madill4e31ad52015-10-29 10:32:57 -0400986 for (unsigned int geometryExeIndex = 0; geometryExeIndex < gl::PRIMITIVE_TYPE_MAX;
987 ++geometryExeIndex)
Brandon Joneseb994362014-09-24 10:27:28 -0700988 {
Jamie Madill4e31ad52015-10-29 10:32:57 -0400989 unsigned int geometryShaderSize = stream->readInt<unsigned int>();
990 if (geometryShaderSize == 0)
991 {
Jamie Madill4e31ad52015-10-29 10:32:57 -0400992 continue;
993 }
994
Brandon Joneseb994362014-09-24 10:27:28 -0700995 const unsigned char *geometryShaderFunction = binary + stream->offset();
Jamie Madill4e31ad52015-10-29 10:32:57 -0400996
Xinghua Caob1239382016-12-13 15:07:05 +0800997 ShaderExecutableD3D *geometryExecutable = nullptr;
Jamie Madillb0a838b2016-11-13 20:02:12 -0500998 ANGLE_TRY(mRenderer->loadExecutable(geometryShaderFunction, geometryShaderSize,
999 SHADER_GEOMETRY, mStreamOutVaryings, separateAttribs,
Xinghua Caob1239382016-12-13 15:07:05 +08001000 &geometryExecutable));
Brandon Joneseb994362014-09-24 10:27:28 -07001001
Xinghua Caob1239382016-12-13 15:07:05 +08001002 if (!geometryExecutable)
Brandon Joneseb994362014-09-24 10:27:28 -07001003 {
Jamie Madillf6113162015-05-07 11:49:21 -04001004 infoLog << "Could not create geometry shader.";
Jamie Madillb0a838b2016-11-13 20:02:12 -05001005 return false;
Brandon Joneseb994362014-09-24 10:27:28 -07001006 }
Xinghua Caob1239382016-12-13 15:07:05 +08001007
1008 mGeometryExecutables[geometryExeIndex].reset(geometryExecutable);
1009
Brandon Joneseb994362014-09-24 10:27:28 -07001010 stream->skip(geometryShaderSize);
1011 }
1012
Xinghua Caob1239382016-12-13 15:07:05 +08001013 unsigned int computeShaderSize = stream->readInt<unsigned int>();
1014 if (computeShaderSize > 0)
1015 {
1016 const unsigned char *computeShaderFunction = binary + stream->offset();
1017
1018 ShaderExecutableD3D *computeExecutable = nullptr;
1019 ANGLE_TRY(mRenderer->loadExecutable(computeShaderFunction, computeShaderSize,
1020 SHADER_COMPUTE, std::vector<D3DVarying>(), false,
1021 &computeExecutable));
1022
1023 if (!computeExecutable)
1024 {
1025 infoLog << "Could not create compute shader.";
1026 return false;
1027 }
1028
1029 mComputeExecutable.reset(computeExecutable);
1030 }
1031
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001032 initializeUniformStorage();
1033
Jamie Madillb0a838b2016-11-13 20:02:12 -05001034 return true;
Brandon Jones22502d52014-08-29 16:58:36 -07001035}
1036
Jamie Madill27a60632017-06-30 15:12:01 -04001037void ProgramD3D::save(const gl::Context *context, gl::BinaryOutputStream *stream)
Brandon Jones22502d52014-08-29 16:58:36 -07001038{
Austin Kinross137b1512015-06-17 16:14:53 -07001039 // Output the DeviceIdentifier before we output any shader code
Jamie Madill334d6152015-10-22 14:00:28 -04001040 // When we load the binary again later, we can validate the device identifier before trying to
1041 // compile any HLSL
Austin Kinross137b1512015-06-17 16:14:53 -07001042 DeviceIdentifier binaryIdentifier = mRenderer->getAdapterIdentifier();
Jamie Madill334d6152015-10-22 14:00:28 -04001043 stream->writeBytes(reinterpret_cast<unsigned char *>(&binaryIdentifier),
1044 sizeof(DeviceIdentifier));
Austin Kinross137b1512015-06-17 16:14:53 -07001045
Jamie Madill2db1fbb2014-12-03 10:58:55 -05001046 stream->writeInt(ANGLE_COMPILE_OPTIMIZATION_LEVEL);
1047
Jamie Madill8047c0d2016-03-07 13:02:12 -05001048 for (int d3dSemantic : mAttribLocationToD3DSemantic)
Jamie Madill63805b42015-08-25 13:17:39 -04001049 {
Jamie Madill8047c0d2016-03-07 13:02:12 -05001050 stream->writeInt(d3dSemantic);
Jamie Madill63805b42015-08-25 13:17:39 -04001051 }
1052
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001053 stream->writeInt(mSamplersPS.size());
1054 for (unsigned int i = 0; i < mSamplersPS.size(); ++i)
1055 {
1056 stream->writeInt(mSamplersPS[i].active);
1057 stream->writeInt(mSamplersPS[i].logicalTextureUnit);
1058 stream->writeInt(mSamplersPS[i].textureType);
1059 }
1060
1061 stream->writeInt(mSamplersVS.size());
1062 for (unsigned int i = 0; i < mSamplersVS.size(); ++i)
1063 {
1064 stream->writeInt(mSamplersVS[i].active);
1065 stream->writeInt(mSamplersVS[i].logicalTextureUnit);
1066 stream->writeInt(mSamplersVS[i].textureType);
1067 }
1068
Xinghua Caob1239382016-12-13 15:07:05 +08001069 stream->writeInt(mSamplersCS.size());
1070 for (unsigned int i = 0; i < mSamplersCS.size(); ++i)
1071 {
1072 stream->writeInt(mSamplersCS[i].active);
1073 stream->writeInt(mSamplersCS[i].logicalTextureUnit);
1074 stream->writeInt(mSamplersCS[i].textureType);
1075 }
1076
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001077 stream->writeInt(mUsedVertexSamplerRange);
1078 stream->writeInt(mUsedPixelSamplerRange);
Xinghua Caob1239382016-12-13 15:07:05 +08001079 stream->writeInt(mUsedComputeSamplerRange);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001080
Jamie Madill62d31cb2015-09-11 13:25:51 -04001081 stream->writeInt(mD3DUniforms.size());
Jamie Madill4a3c2342015-10-08 12:58:45 -04001082 for (const D3DUniform *uniform : mD3DUniforms)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001083 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04001084 // Type, name and arraySize are redundant, so aren't stored in the binary.
Jamie Madille2e406c2016-06-02 13:04:10 -04001085 stream->writeIntOrNegOne(uniform->psRegisterIndex);
1086 stream->writeIntOrNegOne(uniform->vsRegisterIndex);
Xinghua Caob1239382016-12-13 15:07:05 +08001087 stream->writeIntOrNegOne(uniform->csRegisterIndex);
Jamie Madill4a3c2342015-10-08 12:58:45 -04001088 stream->writeInt(uniform->registerCount);
1089 stream->writeInt(uniform->registerElement);
1090 }
1091
Jamie Madill51f522f2016-12-21 15:10:55 -05001092 // Ensure we init the uniform block structure data if we should.
1093 // http://anglebug.com/1637
1094 ensureUniformBlocksInitialized();
1095
Jamie Madill4a3c2342015-10-08 12:58:45 -04001096 stream->writeInt(mD3DUniformBlocks.size());
1097 for (const D3DUniformBlock &uniformBlock : mD3DUniformBlocks)
1098 {
Jamie Madille2e406c2016-06-02 13:04:10 -04001099 stream->writeIntOrNegOne(uniformBlock.psRegisterIndex);
1100 stream->writeIntOrNegOne(uniformBlock.vsRegisterIndex);
Xinghua Caob1239382016-12-13 15:07:05 +08001101 stream->writeIntOrNegOne(uniformBlock.csRegisterIndex);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001102 }
1103
Jamie Madill9fc36822015-11-18 13:08:07 -05001104 stream->writeInt(mStreamOutVaryings.size());
1105 for (const auto &varying : mStreamOutVaryings)
Brandon Joneseb994362014-09-24 10:27:28 -07001106 {
Brandon Joneseb994362014-09-24 10:27:28 -07001107 stream->writeString(varying.semanticName);
1108 stream->writeInt(varying.semanticIndex);
Jamie Madill9fc36822015-11-18 13:08:07 -05001109 stream->writeInt(varying.componentCount);
1110 stream->writeInt(varying.outputSlot);
Brandon Joneseb994362014-09-24 10:27:28 -07001111 }
1112
Brandon Jones22502d52014-08-29 16:58:36 -07001113 stream->writeString(mVertexHLSL);
Jamie Madill334d6152015-10-22 14:00:28 -04001114 stream->writeBytes(reinterpret_cast<unsigned char *>(&mVertexWorkarounds),
Jamie Madill408293f2016-12-20 10:11:45 -05001115 sizeof(angle::CompilerWorkaroundsD3D));
Brandon Jones22502d52014-08-29 16:58:36 -07001116 stream->writeString(mPixelHLSL);
Jamie Madill334d6152015-10-22 14:00:28 -04001117 stream->writeBytes(reinterpret_cast<unsigned char *>(&mPixelWorkarounds),
Jamie Madill408293f2016-12-20 10:11:45 -05001118 sizeof(angle::CompilerWorkaroundsD3D));
Brandon Jones22502d52014-08-29 16:58:36 -07001119 stream->writeInt(mUsesFragDepth);
Martin Radev41ac68e2017-06-06 12:16:58 +03001120 stream->writeInt(mHasANGLEMultiviewEnabled);
1121 stream->writeInt(mUsesViewID);
Brandon Jones44151a92014-09-10 11:32:25 -07001122 stream->writeInt(mUsesPointSize);
Jamie Madill3e14e2b2015-10-29 14:38:53 -04001123 stream->writeInt(mUsesFlatInterpolation);
Brandon Jones22502d52014-08-29 16:58:36 -07001124
Brandon Joneseb994362014-09-24 10:27:28 -07001125 const std::vector<PixelShaderOutputVariable> &pixelShaderKey = mPixelShaderKey;
Brandon Jones22502d52014-08-29 16:58:36 -07001126 stream->writeInt(pixelShaderKey.size());
Jamie Madill334d6152015-10-22 14:00:28 -04001127 for (size_t pixelShaderKeyIndex = 0; pixelShaderKeyIndex < pixelShaderKey.size();
1128 pixelShaderKeyIndex++)
Brandon Jones22502d52014-08-29 16:58:36 -07001129 {
Brandon Joneseb994362014-09-24 10:27:28 -07001130 const PixelShaderOutputVariable &variable = pixelShaderKey[pixelShaderKeyIndex];
Brandon Jones22502d52014-08-29 16:58:36 -07001131 stream->writeInt(variable.type);
1132 stream->writeString(variable.name);
1133 stream->writeString(variable.source);
1134 stream->writeInt(variable.outputIndex);
1135 }
1136
Jamie Madill4e31ad52015-10-29 10:32:57 -04001137 stream->writeString(mGeometryShaderPreamble);
1138
Brandon Joneseb994362014-09-24 10:27:28 -07001139 stream->writeInt(mVertexExecutables.size());
Jamie Madill334d6152015-10-22 14:00:28 -04001140 for (size_t vertexExecutableIndex = 0; vertexExecutableIndex < mVertexExecutables.size();
1141 vertexExecutableIndex++)
Brandon Joneseb994362014-09-24 10:27:28 -07001142 {
Xinghua Caob1239382016-12-13 15:07:05 +08001143 VertexExecutable *vertexExecutable = mVertexExecutables[vertexExecutableIndex].get();
Brandon Joneseb994362014-09-24 10:27:28 -07001144
Jamie Madilld3dfda22015-07-06 08:28:49 -04001145 const auto &inputLayout = vertexExecutable->inputs();
1146 stream->writeInt(inputLayout.size());
1147
1148 for (size_t inputIndex = 0; inputIndex < inputLayout.size(); inputIndex++)
Brandon Joneseb994362014-09-24 10:27:28 -07001149 {
Jamie Madille2e406c2016-06-02 13:04:10 -04001150 stream->writeInt(static_cast<unsigned int>(inputLayout[inputIndex]));
Brandon Joneseb994362014-09-24 10:27:28 -07001151 }
1152
1153 size_t vertexShaderSize = vertexExecutable->shaderExecutable()->getLength();
1154 stream->writeInt(vertexShaderSize);
1155
1156 const uint8_t *vertexBlob = vertexExecutable->shaderExecutable()->getFunction();
1157 stream->writeBytes(vertexBlob, vertexShaderSize);
1158 }
1159
1160 stream->writeInt(mPixelExecutables.size());
Jamie Madill334d6152015-10-22 14:00:28 -04001161 for (size_t pixelExecutableIndex = 0; pixelExecutableIndex < mPixelExecutables.size();
1162 pixelExecutableIndex++)
Brandon Joneseb994362014-09-24 10:27:28 -07001163 {
Xinghua Caob1239382016-12-13 15:07:05 +08001164 PixelExecutable *pixelExecutable = mPixelExecutables[pixelExecutableIndex].get();
Brandon Joneseb994362014-09-24 10:27:28 -07001165
1166 const std::vector<GLenum> outputs = pixelExecutable->outputSignature();
1167 stream->writeInt(outputs.size());
1168 for (size_t outputIndex = 0; outputIndex < outputs.size(); outputIndex++)
1169 {
1170 stream->writeInt(outputs[outputIndex]);
1171 }
1172
1173 size_t pixelShaderSize = pixelExecutable->shaderExecutable()->getLength();
1174 stream->writeInt(pixelShaderSize);
1175
1176 const uint8_t *pixelBlob = pixelExecutable->shaderExecutable()->getFunction();
1177 stream->writeBytes(pixelBlob, pixelShaderSize);
1178 }
1179
Xinghua Caob1239382016-12-13 15:07:05 +08001180 for (auto const &geometryExecutable : mGeometryExecutables)
Brandon Joneseb994362014-09-24 10:27:28 -07001181 {
Xinghua Caob1239382016-12-13 15:07:05 +08001182 if (!geometryExecutable)
Jamie Madill4e31ad52015-10-29 10:32:57 -04001183 {
1184 stream->writeInt(0);
1185 continue;
1186 }
1187
Xinghua Caob1239382016-12-13 15:07:05 +08001188 size_t geometryShaderSize = geometryExecutable->getLength();
Jamie Madill4e31ad52015-10-29 10:32:57 -04001189 stream->writeInt(geometryShaderSize);
Xinghua Caob1239382016-12-13 15:07:05 +08001190 stream->writeBytes(geometryExecutable->getFunction(), geometryShaderSize);
1191 }
1192
1193 if (mComputeExecutable)
1194 {
1195 size_t computeShaderSize = mComputeExecutable->getLength();
1196 stream->writeInt(computeShaderSize);
1197 stream->writeBytes(mComputeExecutable->getFunction(), computeShaderSize);
1198 }
1199 else
1200 {
1201 stream->writeInt(0);
Brandon Joneseb994362014-09-24 10:27:28 -07001202 }
Brandon Jones22502d52014-08-29 16:58:36 -07001203}
1204
Geoff Langc5629752015-12-07 16:29:04 -05001205void ProgramD3D::setBinaryRetrievableHint(bool /* retrievable */)
1206{
1207}
1208
Yunchao He61afff12017-03-14 15:34:03 +08001209void ProgramD3D::setSeparable(bool /* separable */)
1210{
1211}
1212
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001213gl::Error ProgramD3D::getPixelExecutableForCachedOutputLayout(ShaderExecutableD3D **outExecutable,
1214 gl::InfoLog *infoLog)
Brandon Joneseb994362014-09-24 10:27:28 -07001215{
1216 for (size_t executableIndex = 0; executableIndex < mPixelExecutables.size(); executableIndex++)
1217 {
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001218 if (mPixelExecutables[executableIndex]->matchesSignature(mPixelShaderOutputLayoutCache))
Brandon Joneseb994362014-09-24 10:27:28 -07001219 {
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001220 *outExecutable = mPixelExecutables[executableIndex]->shaderExecutable();
Jamie Madill51f522f2016-12-21 15:10:55 -05001221 return gl::NoError();
Brandon Joneseb994362014-09-24 10:27:28 -07001222 }
1223 }
1224
Jamie Madill334d6152015-10-22 14:00:28 -04001225 std::string finalPixelHLSL = mDynamicHLSL->generatePixelShaderForOutputSignature(
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001226 mPixelHLSL, mPixelShaderKey, mUsesFragDepth, mPixelShaderOutputLayoutCache);
Brandon Jones22502d52014-08-29 16:58:36 -07001227
1228 // Generate new pixel executable
Yunchao Hed7297bf2017-04-19 15:27:10 +08001229 ShaderExecutableD3D *pixelExecutable = nullptr;
Jamie Madill97399232014-12-23 12:31:15 -05001230
1231 gl::InfoLog tempInfoLog;
1232 gl::InfoLog *currentInfoLog = infoLog ? infoLog : &tempInfoLog;
1233
Jamie Madill01074252016-11-28 15:55:51 -05001234 ANGLE_TRY(mRenderer->compileToExecutable(
Jamie Madill9fc36822015-11-18 13:08:07 -05001235 *currentInfoLog, finalPixelHLSL, SHADER_PIXEL, mStreamOutVaryings,
Jamie Madill48ef11b2016-04-27 15:21:52 -04001236 (mState.getTransformFeedbackBufferMode() == GL_SEPARATE_ATTRIBS), mPixelWorkarounds,
Jamie Madill01074252016-11-28 15:55:51 -05001237 &pixelExecutable));
Brandon Joneseb994362014-09-24 10:27:28 -07001238
Jamie Madill97399232014-12-23 12:31:15 -05001239 if (pixelExecutable)
1240 {
Xinghua Caob1239382016-12-13 15:07:05 +08001241 mPixelExecutables.push_back(std::unique_ptr<PixelExecutable>(
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001242 new PixelExecutable(mPixelShaderOutputLayoutCache, pixelExecutable)));
Jamie Madill97399232014-12-23 12:31:15 -05001243 }
1244 else if (!infoLog)
Brandon Joneseb994362014-09-24 10:27:28 -07001245 {
Yuly Novikovd73f8522017-01-13 17:48:57 -05001246 ERR() << "Error compiling dynamic pixel executable:" << std::endl
1247 << tempInfoLog.str() << std::endl;
Brandon Joneseb994362014-09-24 10:27:28 -07001248 }
Brandon Jones22502d52014-08-29 16:58:36 -07001249
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001250 *outExecutable = pixelExecutable;
Jamie Madill01074252016-11-28 15:55:51 -05001251 return gl::NoError();
Brandon Jones22502d52014-08-29 16:58:36 -07001252}
1253
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001254gl::Error ProgramD3D::getVertexExecutableForCachedInputLayout(ShaderExecutableD3D **outExectuable,
1255 gl::InfoLog *infoLog)
Brandon Jones22502d52014-08-29 16:58:36 -07001256{
Brandon Joneseb994362014-09-24 10:27:28 -07001257 for (size_t executableIndex = 0; executableIndex < mVertexExecutables.size(); executableIndex++)
1258 {
Jamie Madilld3dfda22015-07-06 08:28:49 -04001259 if (mVertexExecutables[executableIndex]->matchesSignature(mCachedVertexSignature))
Brandon Joneseb994362014-09-24 10:27:28 -07001260 {
Geoff Langb543aff2014-09-30 14:52:54 -04001261 *outExectuable = mVertexExecutables[executableIndex]->shaderExecutable();
Jamie Madill51f522f2016-12-21 15:10:55 -05001262 return gl::NoError();
Brandon Joneseb994362014-09-24 10:27:28 -07001263 }
1264 }
1265
Brandon Jones22502d52014-08-29 16:58:36 -07001266 // Generate new dynamic layout with attribute conversions
Jamie Madillc349ec02015-08-21 16:53:12 -04001267 std::string finalVertexHLSL = mDynamicHLSL->generateVertexShaderForInputLayout(
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001268 mVertexHLSL, mCachedInputLayout, mState.getAttributes());
Brandon Jones22502d52014-08-29 16:58:36 -07001269
1270 // Generate new vertex executable
Yunchao Hed7297bf2017-04-19 15:27:10 +08001271 ShaderExecutableD3D *vertexExecutable = nullptr;
Jamie Madill97399232014-12-23 12:31:15 -05001272
1273 gl::InfoLog tempInfoLog;
1274 gl::InfoLog *currentInfoLog = infoLog ? infoLog : &tempInfoLog;
1275
Jamie Madill01074252016-11-28 15:55:51 -05001276 ANGLE_TRY(mRenderer->compileToExecutable(
Jamie Madill9fc36822015-11-18 13:08:07 -05001277 *currentInfoLog, finalVertexHLSL, SHADER_VERTEX, mStreamOutVaryings,
Jamie Madill48ef11b2016-04-27 15:21:52 -04001278 (mState.getTransformFeedbackBufferMode() == GL_SEPARATE_ATTRIBS), mVertexWorkarounds,
Jamie Madill01074252016-11-28 15:55:51 -05001279 &vertexExecutable));
Geoff Langb543aff2014-09-30 14:52:54 -04001280
Jamie Madill97399232014-12-23 12:31:15 -05001281 if (vertexExecutable)
Brandon Joneseb994362014-09-24 10:27:28 -07001282 {
Xinghua Caob1239382016-12-13 15:07:05 +08001283 mVertexExecutables.push_back(std::unique_ptr<VertexExecutable>(
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001284 new VertexExecutable(mCachedInputLayout, mCachedVertexSignature, vertexExecutable)));
Brandon Joneseb994362014-09-24 10:27:28 -07001285 }
Jamie Madill97399232014-12-23 12:31:15 -05001286 else if (!infoLog)
1287 {
Yuly Novikovd73f8522017-01-13 17:48:57 -05001288 ERR() << "Error compiling dynamic vertex executable:" << std::endl
1289 << tempInfoLog.str() << std::endl;
Jamie Madill97399232014-12-23 12:31:15 -05001290 }
Brandon Jones22502d52014-08-29 16:58:36 -07001291
Geoff Langb543aff2014-09-30 14:52:54 -04001292 *outExectuable = vertexExecutable;
Jamie Madill01074252016-11-28 15:55:51 -05001293 return gl::NoError();
Brandon Jones22502d52014-08-29 16:58:36 -07001294}
1295
Jamie Madill9082b982016-04-27 15:21:51 -04001296gl::Error ProgramD3D::getGeometryExecutableForPrimitiveType(const gl::ContextState &data,
Jamie Madill4e31ad52015-10-29 10:32:57 -04001297 GLenum drawMode,
1298 ShaderExecutableD3D **outExecutable,
1299 gl::InfoLog *infoLog)
1300{
Jamie Madill3e14e2b2015-10-29 14:38:53 -04001301 if (outExecutable)
1302 {
1303 *outExecutable = nullptr;
1304 }
1305
Austin Kinross88829e82016-01-12 13:04:41 -08001306 // Return a null shader if the current rendering doesn't use a geometry shader
1307 if (!usesGeometryShader(drawMode))
Jamie Madill3e14e2b2015-10-29 14:38:53 -04001308 {
Jamie Madill51f522f2016-12-21 15:10:55 -05001309 return gl::NoError();
Jamie Madill3e14e2b2015-10-29 14:38:53 -04001310 }
1311
Jamie Madill4e31ad52015-10-29 10:32:57 -04001312 gl::PrimitiveType geometryShaderType = GetGeometryShaderTypeFromDrawMode(drawMode);
1313
Xinghua Caob1239382016-12-13 15:07:05 +08001314 if (mGeometryExecutables[geometryShaderType])
Jamie Madill4e31ad52015-10-29 10:32:57 -04001315 {
1316 if (outExecutable)
1317 {
Xinghua Caob1239382016-12-13 15:07:05 +08001318 *outExecutable = mGeometryExecutables[geometryShaderType].get();
Jamie Madill4e31ad52015-10-29 10:32:57 -04001319 }
Jamie Madill51f522f2016-12-21 15:10:55 -05001320 return gl::NoError();
Jamie Madill4e31ad52015-10-29 10:32:57 -04001321 }
1322
1323 std::string geometryHLSL = mDynamicHLSL->generateGeometryShaderHLSL(
Jamie Madill48ef11b2016-04-27 15:21:52 -04001324 geometryShaderType, data, mState, mRenderer->presentPathFastEnabled(),
Martin Radev41ac68e2017-06-06 12:16:58 +03001325 mHasANGLEMultiviewEnabled, usesGeometryShaderForPointSpriteEmulation(),
Austin Kinross2a63b3f2016-02-08 12:29:08 -08001326 mGeometryShaderPreamble);
Jamie Madill4e31ad52015-10-29 10:32:57 -04001327
1328 gl::InfoLog tempInfoLog;
1329 gl::InfoLog *currentInfoLog = infoLog ? infoLog : &tempInfoLog;
1330
Xinghua Caob1239382016-12-13 15:07:05 +08001331 ShaderExecutableD3D *geometryExecutable = nullptr;
1332 gl::Error error = mRenderer->compileToExecutable(
Jamie Madill9fc36822015-11-18 13:08:07 -05001333 *currentInfoLog, geometryHLSL, SHADER_GEOMETRY, mStreamOutVaryings,
Jamie Madill408293f2016-12-20 10:11:45 -05001334 (mState.getTransformFeedbackBufferMode() == GL_SEPARATE_ATTRIBS),
Xinghua Caob1239382016-12-13 15:07:05 +08001335 angle::CompilerWorkaroundsD3D(), &geometryExecutable);
Jamie Madill4e31ad52015-10-29 10:32:57 -04001336
1337 if (!infoLog && error.isError())
1338 {
Yuly Novikovd73f8522017-01-13 17:48:57 -05001339 ERR() << "Error compiling dynamic geometry executable:" << std::endl
1340 << tempInfoLog.str() << std::endl;
Jamie Madill4e31ad52015-10-29 10:32:57 -04001341 }
1342
Xinghua Caob1239382016-12-13 15:07:05 +08001343 if (geometryExecutable != nullptr)
1344 {
1345 mGeometryExecutables[geometryShaderType].reset(geometryExecutable);
1346 }
1347
Jamie Madill4e31ad52015-10-29 10:32:57 -04001348 if (outExecutable)
1349 {
Xinghua Caob1239382016-12-13 15:07:05 +08001350 *outExecutable = mGeometryExecutables[geometryShaderType].get();
Jamie Madill4e31ad52015-10-29 10:32:57 -04001351 }
1352 return error;
1353}
1354
Jamie Madill01074252016-11-28 15:55:51 -05001355class ProgramD3D::GetExecutableTask : public Closure
Brandon Jones44151a92014-09-10 11:32:25 -07001356{
Jamie Madill01074252016-11-28 15:55:51 -05001357 public:
1358 GetExecutableTask(ProgramD3D *program)
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05001359 : mProgram(program), mError(gl::NoError()), mInfoLog(), mResult(nullptr)
Brandon Joneseb994362014-09-24 10:27:28 -07001360 {
Brandon Joneseb994362014-09-24 10:27:28 -07001361 }
1362
Jamie Madill01074252016-11-28 15:55:51 -05001363 virtual gl::Error run() = 0;
1364
1365 void operator()() override { mError = run(); }
1366
1367 const gl::Error &getError() const { return mError; }
1368 const gl::InfoLog &getInfoLog() const { return mInfoLog; }
1369 ShaderExecutableD3D *getResult() { return mResult; }
1370
1371 protected:
1372 ProgramD3D *mProgram;
1373 gl::Error mError;
1374 gl::InfoLog mInfoLog;
1375 ShaderExecutableD3D *mResult;
1376};
1377
1378class ProgramD3D::GetVertexExecutableTask : public ProgramD3D::GetExecutableTask
1379{
1380 public:
Jamie Madillbd044ed2017-06-05 12:59:21 -04001381 GetVertexExecutableTask(ProgramD3D *program, const gl::Context *context)
1382 : GetExecutableTask(program), mContext(context)
1383 {
1384 }
Jamie Madill01074252016-11-28 15:55:51 -05001385 gl::Error run() override
1386 {
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001387 mProgram->updateCachedInputLayoutFromShader(mContext);
Jamie Madill01074252016-11-28 15:55:51 -05001388
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001389 ANGLE_TRY(mProgram->getVertexExecutableForCachedInputLayout(&mResult, &mInfoLog));
Jamie Madill01074252016-11-28 15:55:51 -05001390
1391 return gl::NoError();
1392 }
Jamie Madillbd044ed2017-06-05 12:59:21 -04001393
1394 private:
1395 const gl::Context *mContext;
Jamie Madill01074252016-11-28 15:55:51 -05001396};
1397
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001398void ProgramD3D::updateCachedInputLayoutFromShader(const gl::Context *context)
1399{
1400 GetDefaultInputLayoutFromShader(context, mState.getAttachedVertexShader(), &mCachedInputLayout);
1401 VertexExecutable::getSignature(mRenderer, mCachedInputLayout, &mCachedVertexSignature);
1402}
1403
Jamie Madill01074252016-11-28 15:55:51 -05001404class ProgramD3D::GetPixelExecutableTask : public ProgramD3D::GetExecutableTask
1405{
1406 public:
1407 GetPixelExecutableTask(ProgramD3D *program) : GetExecutableTask(program) {}
1408 gl::Error run() override
1409 {
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001410 mProgram->updateCachedOutputLayoutFromShader();
Jamie Madill01074252016-11-28 15:55:51 -05001411
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001412 ANGLE_TRY(mProgram->getPixelExecutableForCachedOutputLayout(&mResult, &mInfoLog));
Jamie Madill01074252016-11-28 15:55:51 -05001413
1414 return gl::NoError();
1415 }
1416};
1417
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001418void ProgramD3D::updateCachedOutputLayoutFromShader()
1419{
1420 GetDefaultOutputLayoutFromShader(mPixelShaderKey, &mPixelShaderOutputLayoutCache);
1421}
1422
Jamie Madill01074252016-11-28 15:55:51 -05001423class ProgramD3D::GetGeometryExecutableTask : public ProgramD3D::GetExecutableTask
1424{
1425 public:
1426 GetGeometryExecutableTask(ProgramD3D *program, const gl::ContextState &contextState)
1427 : GetExecutableTask(program), mContextState(contextState)
1428 {
1429 }
1430
1431 gl::Error run() override
1432 {
1433 // Auto-generate the geometry shader here, if we expect to be using point rendering in
1434 // D3D11.
1435 if (mProgram->usesGeometryShader(GL_POINTS))
1436 {
1437 ANGLE_TRY(mProgram->getGeometryExecutableForPrimitiveType(mContextState, GL_POINTS,
1438 &mResult, &mInfoLog));
1439 }
1440
1441 return gl::NoError();
1442 }
1443
1444 private:
1445 const gl::ContextState &mContextState;
1446};
1447
Xinghua Cao73badc02017-03-29 19:14:53 +08001448gl::Error ProgramD3D::getComputeExecutable(ShaderExecutableD3D **outExecutable)
1449{
1450 if (outExecutable)
1451 {
1452 *outExecutable = mComputeExecutable.get();
1453 }
1454
1455 return gl::NoError();
1456}
1457
Jamie Madill9cf9e872017-06-05 12:59:25 -04001458gl::LinkResult ProgramD3D::compileProgramExecutables(const gl::Context *context,
1459 gl::InfoLog &infoLog)
Jamie Madill01074252016-11-28 15:55:51 -05001460{
1461 // Ensure the compiler is initialized to avoid race conditions.
1462 ANGLE_TRY(mRenderer->ensureHLSLCompilerInitialized());
1463
1464 WorkerThreadPool *workerPool = mRenderer->getWorkerThreadPool();
1465
Jamie Madillbd044ed2017-06-05 12:59:21 -04001466 GetVertexExecutableTask vertexTask(this, context);
Jamie Madill01074252016-11-28 15:55:51 -05001467 GetPixelExecutableTask pixelTask(this);
Jamie Madillbd044ed2017-06-05 12:59:21 -04001468 GetGeometryExecutableTask geometryTask(this, context->getContextState());
Jamie Madill01074252016-11-28 15:55:51 -05001469
1470 std::array<WaitableEvent, 3> waitEvents = {{workerPool->postWorkerTask(&vertexTask),
1471 workerPool->postWorkerTask(&pixelTask),
1472 workerPool->postWorkerTask(&geometryTask)}};
1473
1474 WaitableEvent::WaitMany(&waitEvents);
1475
1476 infoLog << vertexTask.getInfoLog().str();
1477 infoLog << pixelTask.getInfoLog().str();
1478 infoLog << geometryTask.getInfoLog().str();
1479
1480 ANGLE_TRY(vertexTask.getError());
1481 ANGLE_TRY(pixelTask.getError());
1482 ANGLE_TRY(geometryTask.getError());
1483
1484 ShaderExecutableD3D *defaultVertexExecutable = vertexTask.getResult();
1485 ShaderExecutableD3D *defaultPixelExecutable = pixelTask.getResult();
1486 ShaderExecutableD3D *pointGS = geometryTask.getResult();
1487
Jamie Madill48ef11b2016-04-27 15:21:52 -04001488 const ShaderD3D *vertexShaderD3D = GetImplAs<ShaderD3D>(mState.getAttachedVertexShader());
Jamie Madill847638a2015-11-20 13:01:41 -05001489
1490 if (usesGeometryShader(GL_POINTS) && pointGS)
Tibor den Ouden97049c62014-10-06 21:39:16 +02001491 {
Jamie Madill334d6152015-10-22 14:00:28 -04001492 // Geometry shaders are currently only used internally, so there is no corresponding shader
1493 // object at the interface level. For now the geometry shader debug info is prepended to
1494 // the vertex shader.
Tibor den Ouden97049c62014-10-06 21:39:16 +02001495 vertexShaderD3D->appendDebugInfo("// GEOMETRY SHADER BEGIN\n\n");
Jamie Madill847638a2015-11-20 13:01:41 -05001496 vertexShaderD3D->appendDebugInfo(pointGS->getDebugInfo());
Tibor den Ouden97049c62014-10-06 21:39:16 +02001497 vertexShaderD3D->appendDebugInfo("\nGEOMETRY SHADER END\n\n\n");
1498 }
1499
1500 if (defaultVertexExecutable)
1501 {
1502 vertexShaderD3D->appendDebugInfo(defaultVertexExecutable->getDebugInfo());
1503 }
1504
1505 if (defaultPixelExecutable)
1506 {
Jamie Madill76f8fa62015-10-29 10:32:56 -04001507 const ShaderD3D *fragmentShaderD3D =
Jamie Madill48ef11b2016-04-27 15:21:52 -04001508 GetImplAs<ShaderD3D>(mState.getAttachedFragmentShader());
Tibor den Ouden97049c62014-10-06 21:39:16 +02001509 fragmentShaderD3D->appendDebugInfo(defaultPixelExecutable->getDebugInfo());
1510 }
Tibor den Ouden97049c62014-10-06 21:39:16 +02001511
Jamie Madillb0a838b2016-11-13 20:02:12 -05001512 return (defaultVertexExecutable && defaultPixelExecutable &&
1513 (!usesGeometryShader(GL_POINTS) || pointGS));
Brandon Jones18bd4102014-09-22 14:21:44 -07001514}
1515
Jamie Madill9cf9e872017-06-05 12:59:25 -04001516gl::LinkResult ProgramD3D::compileComputeExecutable(const gl::Context *context,
1517 gl::InfoLog &infoLog)
Xinghua Caob1239382016-12-13 15:07:05 +08001518{
1519 // Ensure the compiler is initialized to avoid race conditions.
1520 ANGLE_TRY(mRenderer->ensureHLSLCompilerInitialized());
1521
Jamie Madillbd044ed2017-06-05 12:59:21 -04001522 std::string computeShader = mDynamicHLSL->generateComputeShaderLinkHLSL(context, mState);
Xinghua Caob1239382016-12-13 15:07:05 +08001523
1524 ShaderExecutableD3D *computeExecutable = nullptr;
1525 ANGLE_TRY(mRenderer->compileToExecutable(infoLog, computeShader, SHADER_COMPUTE,
1526 std::vector<D3DVarying>(), false,
1527 angle::CompilerWorkaroundsD3D(), &computeExecutable));
1528
1529 if (computeExecutable == nullptr)
1530 {
Yuly Novikovd73f8522017-01-13 17:48:57 -05001531 ERR() << "Error compiling dynamic compute executable:" << std::endl
1532 << infoLog.str() << std::endl;
Xinghua Caob1239382016-12-13 15:07:05 +08001533 }
1534 else
1535 {
1536 const ShaderD3D *computeShaderD3D = GetImplAs<ShaderD3D>(mState.getAttachedComputeShader());
1537 computeShaderD3D->appendDebugInfo(computeExecutable->getDebugInfo());
1538 mComputeExecutable.reset(computeExecutable);
1539 }
1540
1541 return mComputeExecutable.get() != nullptr;
1542}
1543
Jamie Madill9cf9e872017-06-05 12:59:25 -04001544gl::LinkResult ProgramD3D::link(const gl::Context *context,
1545 const gl::VaryingPacking &packing,
1546 gl::InfoLog &infoLog)
Brandon Jones22502d52014-08-29 16:58:36 -07001547{
Jamie Madillc564c072017-06-01 12:45:42 -04001548 const auto &data = context->getContextState();
Jamie Madill8ecf7f92017-01-13 17:29:52 -05001549
Jamie Madill62d31cb2015-09-11 13:25:51 -04001550 reset();
1551
Jamie Madillbd044ed2017-06-05 12:59:21 -04001552 gl::Shader *computeShader = mState.getAttachedComputeShader();
Xinghua Caob1239382016-12-13 15:07:05 +08001553 if (computeShader)
Austin Kinross02df7962015-07-01 10:03:42 -07001554 {
Xinghua Caob1239382016-12-13 15:07:05 +08001555 mSamplersCS.resize(data.getCaps().maxComputeTextureImageUnits);
1556
Jamie Madillbd044ed2017-06-05 12:59:21 -04001557 defineUniformsAndAssignRegisters(context);
Xinghua Caob1239382016-12-13 15:07:05 +08001558
Jamie Madill9cf9e872017-06-05 12:59:25 -04001559 gl::LinkResult result = compileComputeExecutable(context, infoLog);
Xinghua Caob1239382016-12-13 15:07:05 +08001560 if (result.isError())
Austin Kinross02df7962015-07-01 10:03:42 -07001561 {
Xinghua Caob1239382016-12-13 15:07:05 +08001562 infoLog << result.getError().getMessage();
1563 return result;
1564 }
1565 else if (!result.getResult())
1566 {
1567 infoLog << "Failed to create D3D compute shader.";
1568 return result;
1569 }
1570
Jamie Madillbd044ed2017-06-05 12:59:21 -04001571 initUniformBlockInfo(context, computeShader);
Xinghua Caob1239382016-12-13 15:07:05 +08001572 }
1573 else
1574 {
Jamie Madillbd044ed2017-06-05 12:59:21 -04001575 gl::Shader *vertexShader = mState.getAttachedVertexShader();
1576 gl::Shader *fragmentShader = mState.getAttachedFragmentShader();
Xinghua Caob1239382016-12-13 15:07:05 +08001577
1578 const ShaderD3D *vertexShaderD3D = GetImplAs<ShaderD3D>(vertexShader);
1579 const ShaderD3D *fragmentShaderD3D = GetImplAs<ShaderD3D>(fragmentShader);
1580
1581 mSamplersVS.resize(data.getCaps().maxVertexTextureImageUnits);
1582 mSamplersPS.resize(data.getCaps().maxTextureImageUnits);
1583
1584 vertexShaderD3D->generateWorkarounds(&mVertexWorkarounds);
1585 fragmentShaderD3D->generateWorkarounds(&mPixelWorkarounds);
1586
1587 if (mRenderer->getNativeLimitations().noFrontFacingSupport)
1588 {
1589 if (fragmentShaderD3D->usesFrontFacing())
1590 {
1591 infoLog << "The current renderer doesn't support gl_FrontFacing";
1592 return false;
1593 }
1594 }
1595
1596 // TODO(jmadill): Implement more sophisticated component packing in D3D9.
1597 // We can fail here because we use one semantic per GLSL varying. D3D11 can pack varyings
1598 // intelligently, but D3D9 assumes one semantic per register.
1599 if (mRenderer->getRendererClass() == RENDERER_D3D9 &&
1600 packing.getMaxSemanticIndex() > data.getCaps().maxVaryingVectors)
1601 {
1602 infoLog << "Cannot pack these varyings on D3D9.";
Jamie Madillb0a838b2016-11-13 20:02:12 -05001603 return false;
Austin Kinross02df7962015-07-01 10:03:42 -07001604 }
Xinghua Caob1239382016-12-13 15:07:05 +08001605
1606 ProgramD3DMetadata metadata(mRenderer, vertexShaderD3D, fragmentShaderD3D);
1607 BuiltinVaryingsD3D builtins(metadata, packing);
1608
Jamie Madillbd044ed2017-06-05 12:59:21 -04001609 mDynamicHLSL->generateShaderLinkHLSL(context, mState, metadata, packing, builtins,
1610 &mPixelHLSL, &mVertexHLSL);
Xinghua Caob1239382016-12-13 15:07:05 +08001611
1612 mUsesPointSize = vertexShaderD3D->usesPointSize();
1613 mDynamicHLSL->getPixelShaderOutputKey(data, mState, metadata, &mPixelShaderKey);
1614 mUsesFragDepth = metadata.usesFragDepth();
Martin Radev41ac68e2017-06-06 12:16:58 +03001615 mUsesViewID = metadata.usesViewID();
1616 mHasANGLEMultiviewEnabled = metadata.hasANGLEMultiviewEnabled();
Xinghua Caob1239382016-12-13 15:07:05 +08001617
1618 // Cache if we use flat shading
Jamie Madillbd044ed2017-06-05 12:59:21 -04001619 mUsesFlatInterpolation =
1620 (FindFlatInterpolationVarying(fragmentShader->getVaryings(context)) ||
1621 FindFlatInterpolationVarying(vertexShader->getVaryings(context)));
Xinghua Caob1239382016-12-13 15:07:05 +08001622
1623 if (mRenderer->getMajorShaderModel() >= 4)
1624 {
Martin Radev41ac68e2017-06-06 12:16:58 +03001625 mGeometryShaderPreamble = mDynamicHLSL->generateGeometryShaderPreamble(
1626 packing, builtins, mHasANGLEMultiviewEnabled);
Xinghua Caob1239382016-12-13 15:07:05 +08001627 }
1628
Jamie Madillbd044ed2017-06-05 12:59:21 -04001629 initAttribLocationsToD3DSemantic(context);
Xinghua Caob1239382016-12-13 15:07:05 +08001630
Jamie Madillbd044ed2017-06-05 12:59:21 -04001631 defineUniformsAndAssignRegisters(context);
Xinghua Caob1239382016-12-13 15:07:05 +08001632
1633 gatherTransformFeedbackVaryings(packing, builtins[SHADER_VERTEX]);
1634
Jamie Madill9cf9e872017-06-05 12:59:25 -04001635 gl::LinkResult result = compileProgramExecutables(context, infoLog);
Xinghua Caob1239382016-12-13 15:07:05 +08001636 if (result.isError())
1637 {
1638 infoLog << result.getError().getMessage();
1639 return result;
1640 }
1641 else if (!result.getResult())
1642 {
1643 infoLog << "Failed to create D3D shaders.";
1644 return result;
1645 }
1646
Jamie Madillbd044ed2017-06-05 12:59:21 -04001647 initUniformBlockInfo(context, vertexShader);
1648 initUniformBlockInfo(context, fragmentShader);
Austin Kinross02df7962015-07-01 10:03:42 -07001649 }
1650
Jamie Madillb0a838b2016-11-13 20:02:12 -05001651 return true;
Brandon Jones22502d52014-08-29 16:58:36 -07001652}
1653
Jamie Madill3d3d2f22015-09-23 16:47:51 -04001654GLboolean ProgramD3D::validate(const gl::Caps & /*caps*/, gl::InfoLog * /*infoLog*/)
Jamie Madill36cfd6a2015-08-18 10:46:20 -04001655{
Jamie Madill3d3d2f22015-09-23 16:47:51 -04001656 // TODO(jmadill): Do something useful here?
1657 return GL_TRUE;
Jamie Madill36cfd6a2015-08-18 10:46:20 -04001658}
1659
Jamie Madillbd044ed2017-06-05 12:59:21 -04001660void ProgramD3D::initUniformBlockInfo(const gl::Context *context, gl::Shader *shader)
Jamie Madill62d31cb2015-09-11 13:25:51 -04001661{
Jiajia Qin9b11ea42017-07-11 16:50:08 +08001662 for (const sh::InterfaceBlock &interfaceBlock : shader->getUniformBlocks(context))
Jamie Madill62d31cb2015-09-11 13:25:51 -04001663 {
Xinghua Caob1239382016-12-13 15:07:05 +08001664 if (!interfaceBlock.staticUse && interfaceBlock.layout == sh::BLOCKLAYOUT_PACKED)
Jamie Madill62d31cb2015-09-11 13:25:51 -04001665 continue;
1666
Xinghua Caob1239382016-12-13 15:07:05 +08001667 if (mBlockDataSizes.count(interfaceBlock.name) > 0)
Jamie Madill62d31cb2015-09-11 13:25:51 -04001668 continue;
1669
Xinghua Caob1239382016-12-13 15:07:05 +08001670 size_t dataSize = getUniformBlockInfo(interfaceBlock);
1671 mBlockDataSizes[interfaceBlock.name] = dataSize;
Jamie Madill62d31cb2015-09-11 13:25:51 -04001672 }
Jamie Madill4a3c2342015-10-08 12:58:45 -04001673}
Jamie Madill62d31cb2015-09-11 13:25:51 -04001674
Jamie Madill51f522f2016-12-21 15:10:55 -05001675void ProgramD3D::ensureUniformBlocksInitialized()
Jamie Madill4a3c2342015-10-08 12:58:45 -04001676{
Jamie Madill51f522f2016-12-21 15:10:55 -05001677 // Lazy init.
1678 if (mState.getUniformBlocks().empty() || !mD3DUniformBlocks.empty())
1679 {
1680 return;
1681 }
Jamie Madill62d31cb2015-09-11 13:25:51 -04001682
1683 // Assign registers and update sizes.
Xinghua Caob1239382016-12-13 15:07:05 +08001684 const ShaderD3D *vertexShaderD3D = SafeGetImplAs<ShaderD3D>(mState.getAttachedVertexShader());
1685 const ShaderD3D *fragmentShaderD3D =
1686 SafeGetImplAs<ShaderD3D>(mState.getAttachedFragmentShader());
1687 const ShaderD3D *computeShaderD3D = SafeGetImplAs<ShaderD3D>(mState.getAttachedComputeShader());
Jamie Madill62d31cb2015-09-11 13:25:51 -04001688
Jamie Madill48ef11b2016-04-27 15:21:52 -04001689 for (const gl::UniformBlock &uniformBlock : mState.getUniformBlocks())
Jamie Madill62d31cb2015-09-11 13:25:51 -04001690 {
1691 unsigned int uniformBlockElement = uniformBlock.isArray ? uniformBlock.arrayElement : 0;
1692
Jamie Madill4a3c2342015-10-08 12:58:45 -04001693 D3DUniformBlock d3dUniformBlock;
1694
Jamie Madill62d31cb2015-09-11 13:25:51 -04001695 if (uniformBlock.vertexStaticUse)
1696 {
Xinghua Caob1239382016-12-13 15:07:05 +08001697 ASSERT(vertexShaderD3D != nullptr);
Jiajia Qin9b11ea42017-07-11 16:50:08 +08001698 unsigned int baseRegister = vertexShaderD3D->getUniformBlockRegister(uniformBlock.name);
Jamie Madill4a3c2342015-10-08 12:58:45 -04001699 d3dUniformBlock.vsRegisterIndex = baseRegister + uniformBlockElement;
Jamie Madill62d31cb2015-09-11 13:25:51 -04001700 }
1701
1702 if (uniformBlock.fragmentStaticUse)
1703 {
Xinghua Caob1239382016-12-13 15:07:05 +08001704 ASSERT(fragmentShaderD3D != nullptr);
Jamie Madill62d31cb2015-09-11 13:25:51 -04001705 unsigned int baseRegister =
Jiajia Qin9b11ea42017-07-11 16:50:08 +08001706 fragmentShaderD3D->getUniformBlockRegister(uniformBlock.name);
Jamie Madill4a3c2342015-10-08 12:58:45 -04001707 d3dUniformBlock.psRegisterIndex = baseRegister + uniformBlockElement;
Jamie Madill62d31cb2015-09-11 13:25:51 -04001708 }
1709
Xinghua Caob1239382016-12-13 15:07:05 +08001710 if (uniformBlock.computeStaticUse)
1711 {
1712 ASSERT(computeShaderD3D != nullptr);
1713 unsigned int baseRegister =
Jiajia Qin9b11ea42017-07-11 16:50:08 +08001714 computeShaderD3D->getUniformBlockRegister(uniformBlock.name);
Xinghua Caob1239382016-12-13 15:07:05 +08001715 d3dUniformBlock.csRegisterIndex = baseRegister + uniformBlockElement;
1716 }
1717
Jamie Madill4a3c2342015-10-08 12:58:45 -04001718 mD3DUniformBlocks.push_back(d3dUniformBlock);
Jamie Madill62d31cb2015-09-11 13:25:51 -04001719 }
1720}
1721
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001722void ProgramD3D::initializeUniformStorage()
Brandon Jonesc9610c52014-08-25 17:02:59 -07001723{
1724 // Compute total default block size
Jamie Madill334d6152015-10-22 14:00:28 -04001725 unsigned int vertexRegisters = 0;
Brandon Jonesc9610c52014-08-25 17:02:59 -07001726 unsigned int fragmentRegisters = 0;
Xinghua Caob1239382016-12-13 15:07:05 +08001727 unsigned int computeRegisters = 0;
Jamie Madill62d31cb2015-09-11 13:25:51 -04001728 for (const D3DUniform *d3dUniform : mD3DUniforms)
Brandon Jonesc9610c52014-08-25 17:02:59 -07001729 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04001730 if (!d3dUniform->isSampler())
Brandon Jonesc9610c52014-08-25 17:02:59 -07001731 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04001732 if (d3dUniform->isReferencedByVertexShader())
Brandon Jonesc9610c52014-08-25 17:02:59 -07001733 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04001734 vertexRegisters = std::max(vertexRegisters,
1735 d3dUniform->vsRegisterIndex + d3dUniform->registerCount);
Brandon Jonesc9610c52014-08-25 17:02:59 -07001736 }
Jamie Madill62d31cb2015-09-11 13:25:51 -04001737 if (d3dUniform->isReferencedByFragmentShader())
Brandon Jonesc9610c52014-08-25 17:02:59 -07001738 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04001739 fragmentRegisters = std::max(
1740 fragmentRegisters, d3dUniform->psRegisterIndex + d3dUniform->registerCount);
Brandon Jonesc9610c52014-08-25 17:02:59 -07001741 }
Xinghua Caob1239382016-12-13 15:07:05 +08001742 if (d3dUniform->isReferencedByComputeShader())
1743 {
1744 computeRegisters = std::max(
1745 computeRegisters, d3dUniform->csRegisterIndex + d3dUniform->registerCount);
1746 }
Brandon Jonesc9610c52014-08-25 17:02:59 -07001747 }
1748 }
1749
Xinghua Caob1239382016-12-13 15:07:05 +08001750 mVertexUniformStorage =
1751 std::unique_ptr<UniformStorageD3D>(mRenderer->createUniformStorage(vertexRegisters * 16u));
1752 mFragmentUniformStorage = std::unique_ptr<UniformStorageD3D>(
1753 mRenderer->createUniformStorage(fragmentRegisters * 16u));
1754 mComputeUniformStorage =
1755 std::unique_ptr<UniformStorageD3D>(mRenderer->createUniformStorage(computeRegisters * 16u));
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04001756
1757 // Iterate the uniforms again to assign data pointers to default block uniforms.
1758 for (D3DUniform *d3dUniform : mD3DUniforms)
1759 {
1760 if (d3dUniform->isSampler())
1761 {
1762 d3dUniform->mSamplerData.resize(d3dUniform->elementCount(), 0);
1763 continue;
1764 }
1765
1766 if (d3dUniform->isReferencedByVertexShader())
1767 {
1768 d3dUniform->vsData = mVertexUniformStorage->getDataPointer(d3dUniform->vsRegisterIndex,
1769 d3dUniform->registerElement);
1770 }
1771
1772 if (d3dUniform->isReferencedByFragmentShader())
1773 {
1774 d3dUniform->psData = mFragmentUniformStorage->getDataPointer(
1775 d3dUniform->psRegisterIndex, d3dUniform->registerElement);
1776 }
1777
1778 if (d3dUniform->isReferencedByComputeShader())
1779 {
1780 d3dUniform->csData = mComputeUniformStorage->getDataPointer(
1781 d3dUniform->csRegisterIndex, d3dUniform->registerElement);
1782 }
1783 }
Brandon Jonesc9610c52014-08-25 17:02:59 -07001784}
1785
Jamie Madill561ed3a2017-08-31 16:48:09 -04001786gl::Error ProgramD3D::applyUniforms()
Brandon Jones18bd4102014-09-22 14:21:44 -07001787{
Olli Etuahoe5df3062015-11-18 13:45:19 +02001788 ASSERT(!mDirtySamplerMapping);
Jamie Madill561ed3a2017-08-31 16:48:09 -04001789 ANGLE_TRY(mRenderer->applyUniforms(*this, mD3DUniforms));
1790 mUniformsDirty = false;
Jamie Madill51f522f2016-12-21 15:10:55 -05001791 return gl::NoError();
Brandon Jones18bd4102014-09-22 14:21:44 -07001792}
1793
Xinghua Cao73badc02017-03-29 19:14:53 +08001794gl::Error ProgramD3D::applyComputeUniforms()
1795{
1796 ASSERT(!mDirtySamplerMapping);
1797 ANGLE_TRY(mRenderer->applyComputeUniforms(*this, mD3DUniforms));
Jamie Madill561ed3a2017-08-31 16:48:09 -04001798 mUniformsDirty = false;
Xinghua Cao73badc02017-03-29 19:14:53 +08001799 return gl::NoError();
1800}
1801
Jamie Madill9082b982016-04-27 15:21:51 -04001802gl::Error ProgramD3D::applyUniformBuffers(const gl::ContextState &data)
Brandon Jones18bd4102014-09-22 14:21:44 -07001803{
Jamie Madill48ef11b2016-04-27 15:21:52 -04001804 if (mState.getUniformBlocks().empty())
Jamie Madill4a3c2342015-10-08 12:58:45 -04001805 {
Jamie Madill51f522f2016-12-21 15:10:55 -05001806 return gl::NoError();
Jamie Madill4a3c2342015-10-08 12:58:45 -04001807 }
1808
Jamie Madill51f522f2016-12-21 15:10:55 -05001809 ensureUniformBlocksInitialized();
Jamie Madill4a3c2342015-10-08 12:58:45 -04001810
Jamie Madill03260fa2015-06-22 13:57:22 -04001811 mVertexUBOCache.clear();
1812 mFragmentUBOCache.clear();
Brandon Jones18bd4102014-09-22 14:21:44 -07001813
1814 const unsigned int reservedBuffersInVS = mRenderer->getReservedVertexUniformBuffers();
1815 const unsigned int reservedBuffersInFS = mRenderer->getReservedFragmentUniformBuffers();
1816
Jamie Madill4a3c2342015-10-08 12:58:45 -04001817 for (unsigned int uniformBlockIndex = 0; uniformBlockIndex < mD3DUniformBlocks.size();
Jamie Madill62d31cb2015-09-11 13:25:51 -04001818 uniformBlockIndex++)
Brandon Jones18bd4102014-09-22 14:21:44 -07001819 {
Jamie Madill4a3c2342015-10-08 12:58:45 -04001820 const D3DUniformBlock &uniformBlock = mD3DUniformBlocks[uniformBlockIndex];
Jamie Madill48ef11b2016-04-27 15:21:52 -04001821 GLuint blockBinding = mState.getUniformBlockBinding(uniformBlockIndex);
Brandon Jones18bd4102014-09-22 14:21:44 -07001822
Brandon Jones18bd4102014-09-22 14:21:44 -07001823 // Unnecessary to apply an unreferenced standard or shared UBO
Jamie Madill4a3c2342015-10-08 12:58:45 -04001824 if (!uniformBlock.vertexStaticUse() && !uniformBlock.fragmentStaticUse())
Brandon Jones18bd4102014-09-22 14:21:44 -07001825 {
1826 continue;
1827 }
1828
Jamie Madill4a3c2342015-10-08 12:58:45 -04001829 if (uniformBlock.vertexStaticUse())
Brandon Jones18bd4102014-09-22 14:21:44 -07001830 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04001831 unsigned int registerIndex = uniformBlock.vsRegisterIndex - reservedBuffersInVS;
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001832 ASSERT(registerIndex < data.getCaps().maxVertexUniformBlocks);
Jamie Madill03260fa2015-06-22 13:57:22 -04001833
Jamie Madill969194d2015-07-20 14:36:56 -04001834 if (mVertexUBOCache.size() <= registerIndex)
Jamie Madill03260fa2015-06-22 13:57:22 -04001835 {
1836 mVertexUBOCache.resize(registerIndex + 1, -1);
1837 }
1838
1839 ASSERT(mVertexUBOCache[registerIndex] == -1);
1840 mVertexUBOCache[registerIndex] = blockBinding;
Brandon Jones18bd4102014-09-22 14:21:44 -07001841 }
1842
Jamie Madill4a3c2342015-10-08 12:58:45 -04001843 if (uniformBlock.fragmentStaticUse())
Brandon Jones18bd4102014-09-22 14:21:44 -07001844 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04001845 unsigned int registerIndex = uniformBlock.psRegisterIndex - reservedBuffersInFS;
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001846 ASSERT(registerIndex < data.getCaps().maxFragmentUniformBlocks);
Jamie Madill03260fa2015-06-22 13:57:22 -04001847
1848 if (mFragmentUBOCache.size() <= registerIndex)
1849 {
1850 mFragmentUBOCache.resize(registerIndex + 1, -1);
1851 }
1852
1853 ASSERT(mFragmentUBOCache[registerIndex] == -1);
1854 mFragmentUBOCache[registerIndex] = blockBinding;
Brandon Jones18bd4102014-09-22 14:21:44 -07001855 }
1856 }
1857
Jamie Madill03260fa2015-06-22 13:57:22 -04001858 return mRenderer->setUniformBuffers(data, mVertexUBOCache, mFragmentUBOCache);
Brandon Jones18bd4102014-09-22 14:21:44 -07001859}
1860
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001861void ProgramD3D::dirtyAllUniforms()
Brandon Jones18bd4102014-09-22 14:21:44 -07001862{
Jamie Madill561ed3a2017-08-31 16:48:09 -04001863 mUniformsDirty = true;
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001864}
1865
Jamie Madill334d6152015-10-22 14:00:28 -04001866void ProgramD3D::setUniform1fv(GLint location, GLsizei count, const GLfloat *v)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001867{
Jamie Madill134f93d2017-08-31 17:11:00 -04001868 setUniformInternal(location, count, v, gl::GetUniformTypeInfo(GL_FLOAT));
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001869}
1870
1871void ProgramD3D::setUniform2fv(GLint location, GLsizei count, const GLfloat *v)
1872{
Jamie Madill134f93d2017-08-31 17:11:00 -04001873 setUniformInternal(location, count, v, gl::GetUniformTypeInfo(GL_FLOAT_VEC2));
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001874}
1875
1876void ProgramD3D::setUniform3fv(GLint location, GLsizei count, const GLfloat *v)
1877{
Jamie Madill134f93d2017-08-31 17:11:00 -04001878 setUniformInternal(location, count, v, gl::GetUniformTypeInfo(GL_FLOAT_VEC3));
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001879}
1880
1881void ProgramD3D::setUniform4fv(GLint location, GLsizei count, const GLfloat *v)
1882{
Jamie Madill134f93d2017-08-31 17:11:00 -04001883 setUniformInternal(location, count, v, gl::GetUniformTypeInfo(GL_FLOAT_VEC4));
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001884}
1885
Jamie Madill334d6152015-10-22 14:00:28 -04001886void ProgramD3D::setUniformMatrix2fv(GLint location,
1887 GLsizei count,
1888 GLboolean transpose,
1889 const GLfloat *value)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001890{
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04001891 setUniformMatrixfvInternal<2, 2>(location, count, transpose, value, GL_FLOAT_MAT2);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001892}
1893
Jamie Madill334d6152015-10-22 14:00:28 -04001894void ProgramD3D::setUniformMatrix3fv(GLint location,
1895 GLsizei count,
1896 GLboolean transpose,
1897 const GLfloat *value)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001898{
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04001899 setUniformMatrixfvInternal<3, 3>(location, count, transpose, value, GL_FLOAT_MAT3);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001900}
1901
Jamie Madill334d6152015-10-22 14:00:28 -04001902void ProgramD3D::setUniformMatrix4fv(GLint location,
1903 GLsizei count,
1904 GLboolean transpose,
1905 const GLfloat *value)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001906{
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04001907 setUniformMatrixfvInternal<4, 4>(location, count, transpose, value, GL_FLOAT_MAT4);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001908}
1909
Jamie Madill334d6152015-10-22 14:00:28 -04001910void ProgramD3D::setUniformMatrix2x3fv(GLint location,
1911 GLsizei count,
1912 GLboolean transpose,
1913 const GLfloat *value)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001914{
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04001915 setUniformMatrixfvInternal<2, 3>(location, count, transpose, value, GL_FLOAT_MAT2x3);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001916}
1917
Jamie Madill334d6152015-10-22 14:00:28 -04001918void ProgramD3D::setUniformMatrix3x2fv(GLint location,
1919 GLsizei count,
1920 GLboolean transpose,
1921 const GLfloat *value)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001922{
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04001923 setUniformMatrixfvInternal<3, 2>(location, count, transpose, value, GL_FLOAT_MAT3x2);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001924}
1925
Jamie Madill334d6152015-10-22 14:00:28 -04001926void ProgramD3D::setUniformMatrix2x4fv(GLint location,
1927 GLsizei count,
1928 GLboolean transpose,
1929 const GLfloat *value)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001930{
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04001931 setUniformMatrixfvInternal<2, 4>(location, count, transpose, value, GL_FLOAT_MAT2x4);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001932}
1933
Jamie Madill334d6152015-10-22 14:00:28 -04001934void ProgramD3D::setUniformMatrix4x2fv(GLint location,
1935 GLsizei count,
1936 GLboolean transpose,
1937 const GLfloat *value)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001938{
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04001939 setUniformMatrixfvInternal<4, 2>(location, count, transpose, value, GL_FLOAT_MAT4x2);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001940}
1941
Jamie Madill334d6152015-10-22 14:00:28 -04001942void ProgramD3D::setUniformMatrix3x4fv(GLint location,
1943 GLsizei count,
1944 GLboolean transpose,
1945 const GLfloat *value)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001946{
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04001947 setUniformMatrixfvInternal<3, 4>(location, count, transpose, value, GL_FLOAT_MAT3x4);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001948}
1949
Jamie Madill334d6152015-10-22 14:00:28 -04001950void ProgramD3D::setUniformMatrix4x3fv(GLint location,
1951 GLsizei count,
1952 GLboolean transpose,
1953 const GLfloat *value)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001954{
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04001955 setUniformMatrixfvInternal<4, 3>(location, count, transpose, value, GL_FLOAT_MAT4x3);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001956}
1957
1958void ProgramD3D::setUniform1iv(GLint location, GLsizei count, const GLint *v)
1959{
Jamie Madill134f93d2017-08-31 17:11:00 -04001960 setUniformInternal(location, count, v, gl::GetUniformTypeInfo(GL_INT));
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001961}
1962
1963void ProgramD3D::setUniform2iv(GLint location, GLsizei count, const GLint *v)
1964{
Jamie Madill134f93d2017-08-31 17:11:00 -04001965 setUniformInternal(location, count, v, gl::GetUniformTypeInfo(GL_INT_VEC2));
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001966}
1967
1968void ProgramD3D::setUniform3iv(GLint location, GLsizei count, const GLint *v)
1969{
Jamie Madill134f93d2017-08-31 17:11:00 -04001970 setUniformInternal(location, count, v, gl::GetUniformTypeInfo(GL_INT_VEC3));
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001971}
1972
1973void ProgramD3D::setUniform4iv(GLint location, GLsizei count, const GLint *v)
1974{
Jamie Madill134f93d2017-08-31 17:11:00 -04001975 setUniformInternal(location, count, v, gl::GetUniformTypeInfo(GL_INT_VEC4));
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001976}
1977
1978void ProgramD3D::setUniform1uiv(GLint location, GLsizei count, const GLuint *v)
1979{
Jamie Madill134f93d2017-08-31 17:11:00 -04001980 setUniformInternal(location, count, v, gl::GetUniformTypeInfo(GL_UNSIGNED_INT));
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001981}
1982
1983void ProgramD3D::setUniform2uiv(GLint location, GLsizei count, const GLuint *v)
1984{
Jamie Madill134f93d2017-08-31 17:11:00 -04001985 setUniformInternal(location, count, v, gl::GetUniformTypeInfo(GL_UNSIGNED_INT_VEC2));
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001986}
1987
1988void ProgramD3D::setUniform3uiv(GLint location, GLsizei count, const GLuint *v)
1989{
Jamie Madill134f93d2017-08-31 17:11:00 -04001990 setUniformInternal(location, count, v, gl::GetUniformTypeInfo(GL_UNSIGNED_INT_VEC3));
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001991}
1992
1993void ProgramD3D::setUniform4uiv(GLint location, GLsizei count, const GLuint *v)
1994{
Jamie Madill134f93d2017-08-31 17:11:00 -04001995 setUniformInternal(location, count, v, gl::GetUniformTypeInfo(GL_UNSIGNED_INT_VEC4));
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001996}
1997
Jamie Madill4a3c2342015-10-08 12:58:45 -04001998void ProgramD3D::setUniformBlockBinding(GLuint /*uniformBlockIndex*/,
1999 GLuint /*uniformBlockBinding*/)
Geoff Lang5d124a62015-09-15 13:03:27 -04002000{
2001}
2002
Jamie Madillbd044ed2017-06-05 12:59:21 -04002003void ProgramD3D::defineUniformsAndAssignRegisters(const gl::Context *context)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002004{
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002005 D3DUniformMap uniformMap;
Jamie Madillbd044ed2017-06-05 12:59:21 -04002006 gl::Shader *computeShader = mState.getAttachedComputeShader();
Xinghua Caob1239382016-12-13 15:07:05 +08002007 if (computeShader)
Jamie Madill417df922017-01-12 09:23:07 -05002008 {
Jamie Madillbd044ed2017-06-05 12:59:21 -04002009 for (const sh::Uniform &computeUniform : computeShader->getUniforms(context))
Jamie Madillfb536032015-09-11 13:19:49 -04002010 {
Xinghua Caob1239382016-12-13 15:07:05 +08002011 if (computeUniform.staticUse)
2012 {
2013 defineUniformBase(computeShader, computeUniform, &uniformMap);
2014 }
Jamie Madillfb536032015-09-11 13:19:49 -04002015 }
2016 }
Xinghua Caob1239382016-12-13 15:07:05 +08002017 else
Jamie Madillfb536032015-09-11 13:19:49 -04002018 {
Jamie Madillbd044ed2017-06-05 12:59:21 -04002019 gl::Shader *vertexShader = mState.getAttachedVertexShader();
2020 for (const sh::Uniform &vertexUniform : vertexShader->getUniforms(context))
Jamie Madillfb536032015-09-11 13:19:49 -04002021 {
Xinghua Caob1239382016-12-13 15:07:05 +08002022 if (vertexUniform.staticUse)
2023 {
2024 defineUniformBase(vertexShader, vertexUniform, &uniformMap);
2025 }
2026 }
2027
Jamie Madillbd044ed2017-06-05 12:59:21 -04002028 gl::Shader *fragmentShader = mState.getAttachedFragmentShader();
2029 for (const sh::Uniform &fragmentUniform : fragmentShader->getUniforms(context))
Xinghua Caob1239382016-12-13 15:07:05 +08002030 {
2031 if (fragmentUniform.staticUse)
2032 {
2033 defineUniformBase(fragmentShader, fragmentUniform, &uniformMap);
2034 }
Jamie Madillfb536032015-09-11 13:19:49 -04002035 }
2036 }
2037
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002038 // Initialize the D3DUniform list to mirror the indexing of the GL layer.
Jamie Madill48ef11b2016-04-27 15:21:52 -04002039 for (const gl::LinkedUniform &glUniform : mState.getUniforms())
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002040 {
2041 if (!glUniform.isInDefaultBlock())
2042 continue;
2043
2044 auto mapEntry = uniformMap.find(glUniform.name);
2045 ASSERT(mapEntry != uniformMap.end());
2046 mD3DUniforms.push_back(mapEntry->second);
2047 }
2048
Jamie Madill62d31cb2015-09-11 13:25:51 -04002049 assignAllSamplerRegisters();
Jamie Madillfb536032015-09-11 13:19:49 -04002050 initializeUniformStorage();
Jamie Madillfb536032015-09-11 13:19:49 -04002051}
2052
Jamie Madill91445bc2015-09-23 16:47:53 -04002053void ProgramD3D::defineUniformBase(const gl::Shader *shader,
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002054 const sh::Uniform &uniform,
2055 D3DUniformMap *uniformMap)
Jamie Madillfb536032015-09-11 13:19:49 -04002056{
Olli Etuaho96963162016-03-21 11:54:33 +02002057 // Samplers get their registers assigned in assignAllSamplerRegisters.
2058 if (uniform.isBuiltIn() || gl::IsSamplerType(uniform.type))
Jamie Madillfb536032015-09-11 13:19:49 -04002059 {
Jamie Madill91445bc2015-09-23 16:47:53 -04002060 defineUniform(shader->getType(), uniform, uniform.name, nullptr, uniformMap);
Jamie Madill55def582015-05-04 11:24:57 -04002061 return;
2062 }
2063
Jamie Madill91445bc2015-09-23 16:47:53 -04002064 const ShaderD3D *shaderD3D = GetImplAs<ShaderD3D>(shader);
2065
2066 unsigned int startRegister = shaderD3D->getUniformRegister(uniform.name);
2067 ShShaderOutput outputType = shaderD3D->getCompilerOutputType();
Jamie Madillcc2ed612017-03-14 15:59:00 -04002068 sh::HLSLBlockEncoder encoder(sh::HLSLBlockEncoder::GetStrategyFor(outputType), true);
Jamie Madill62d31cb2015-09-11 13:25:51 -04002069 encoder.skipRegisters(startRegister);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002070
Jamie Madill91445bc2015-09-23 16:47:53 -04002071 defineUniform(shader->getType(), uniform, uniform.name, &encoder, uniformMap);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002072}
2073
Jamie Madill62d31cb2015-09-11 13:25:51 -04002074D3DUniform *ProgramD3D::getD3DUniformByName(const std::string &name)
2075{
2076 for (D3DUniform *d3dUniform : mD3DUniforms)
2077 {
2078 if (d3dUniform->name == name)
2079 {
2080 return d3dUniform;
2081 }
2082 }
2083
2084 return nullptr;
2085}
2086
Jamie Madill91445bc2015-09-23 16:47:53 -04002087void ProgramD3D::defineUniform(GLenum shaderType,
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002088 const sh::ShaderVariable &uniform,
2089 const std::string &fullName,
2090 sh::HLSLBlockEncoder *encoder,
2091 D3DUniformMap *uniformMap)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002092{
2093 if (uniform.isStruct())
2094 {
2095 for (unsigned int elementIndex = 0; elementIndex < uniform.elementCount(); elementIndex++)
2096 {
2097 const std::string &elementString = (uniform.isArray() ? ArrayString(elementIndex) : "");
2098
Jamie Madill55def582015-05-04 11:24:57 -04002099 if (encoder)
2100 encoder->enterAggregateType();
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002101
2102 for (size_t fieldIndex = 0; fieldIndex < uniform.fields.size(); fieldIndex++)
2103 {
Jamie Madill334d6152015-10-22 14:00:28 -04002104 const sh::ShaderVariable &field = uniform.fields[fieldIndex];
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002105 const std::string &fieldFullName = (fullName + elementString + "." + field.name);
2106
Olli Etuaho96963162016-03-21 11:54:33 +02002107 // Samplers get their registers assigned in assignAllSamplerRegisters.
2108 // Also they couldn't use the same encoder as the rest of the struct, since they are
2109 // extracted out of the struct by the shader translator.
2110 if (gl::IsSamplerType(field.type))
2111 {
2112 defineUniform(shaderType, field, fieldFullName, nullptr, uniformMap);
2113 }
2114 else
2115 {
2116 defineUniform(shaderType, field, fieldFullName, encoder, uniformMap);
2117 }
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002118 }
2119
Jamie Madill55def582015-05-04 11:24:57 -04002120 if (encoder)
2121 encoder->exitAggregateType();
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002122 }
Jamie Madill62d31cb2015-09-11 13:25:51 -04002123 return;
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002124 }
Jamie Madill62d31cb2015-09-11 13:25:51 -04002125
2126 // Not a struct. Arrays are treated as aggregate types.
2127 if (uniform.isArray() && encoder)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002128 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04002129 encoder->enterAggregateType();
2130 }
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002131
Jamie Madill62d31cb2015-09-11 13:25:51 -04002132 // Advance the uniform offset, to track registers allocation for structs
2133 sh::BlockMemberInfo blockInfo =
2134 encoder ? encoder->encodeType(uniform.type, uniform.arraySize, false)
2135 : sh::BlockMemberInfo::getDefaultBlockInfo();
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002136
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002137 auto uniformMapEntry = uniformMap->find(fullName);
2138 D3DUniform *d3dUniform = nullptr;
Jamie Madill2857f482015-02-09 15:35:29 -05002139
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002140 if (uniformMapEntry != uniformMap->end())
Jamie Madill62d31cb2015-09-11 13:25:51 -04002141 {
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002142 d3dUniform = uniformMapEntry->second;
2143 }
2144 else
2145 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04002146 d3dUniform = new D3DUniform(uniform.type, fullName, uniform.arraySize, true);
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002147 (*uniformMap)[fullName] = d3dUniform;
Jamie Madill62d31cb2015-09-11 13:25:51 -04002148 }
2149
2150 if (encoder)
2151 {
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002152 d3dUniform->registerElement =
2153 static_cast<unsigned int>(sh::HLSLBlockEncoder::getBlockRegisterElement(blockInfo));
Jamie Madill62d31cb2015-09-11 13:25:51 -04002154 unsigned int reg =
2155 static_cast<unsigned int>(sh::HLSLBlockEncoder::getBlockRegister(blockInfo));
Jamie Madill91445bc2015-09-23 16:47:53 -04002156 if (shaderType == GL_FRAGMENT_SHADER)
Jamie Madill62d31cb2015-09-11 13:25:51 -04002157 {
2158 d3dUniform->psRegisterIndex = reg;
2159 }
Xinghua Caob1239382016-12-13 15:07:05 +08002160 else if (shaderType == GL_VERTEX_SHADER)
2161 {
2162 d3dUniform->vsRegisterIndex = reg;
2163 }
Jamie Madill91445bc2015-09-23 16:47:53 -04002164 else
Jamie Madill62d31cb2015-09-11 13:25:51 -04002165 {
Xinghua Caob1239382016-12-13 15:07:05 +08002166 ASSERT(shaderType == GL_COMPUTE_SHADER);
2167 d3dUniform->csRegisterIndex = reg;
Jamie Madill62d31cb2015-09-11 13:25:51 -04002168 }
Jamie Madillfb536032015-09-11 13:19:49 -04002169
2170 // Arrays are treated as aggregate types
Jamie Madill62d31cb2015-09-11 13:25:51 -04002171 if (uniform.isArray())
Jamie Madillfb536032015-09-11 13:19:49 -04002172 {
2173 encoder->exitAggregateType();
2174 }
2175 }
2176}
2177
Jamie Madill134f93d2017-08-31 17:11:00 -04002178// Assume count is already clamped.
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002179template <typename T>
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04002180void ProgramD3D::setUniformImpl(const gl::VariableLocation &locationInfo,
Jamie Madill134f93d2017-08-31 17:11:00 -04002181 GLsizei count,
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04002182 const T *v,
2183 uint8_t *targetData,
Jamie Madill134f93d2017-08-31 17:11:00 -04002184 const gl::UniformTypeInfo &uniformTypeInfo)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002185{
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04002186 D3DUniform *targetUniform = mD3DUniforms[locationInfo.index];
Jamie Madill134f93d2017-08-31 17:11:00 -04002187 const int components = uniformTypeInfo.componentCount;
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04002188 unsigned int arrayElement = locationInfo.element;
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002189
Jamie Madill134f93d2017-08-31 17:11:00 -04002190 if (targetUniform->type == uniformTypeInfo.type)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002191 {
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04002192 T *target = reinterpret_cast<T *>(targetData) + arrayElement * 4;
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002193
Jamie Madill134f93d2017-08-31 17:11:00 -04002194 for (GLint i = 0; i < count; i++)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002195 {
Jamie Madill334d6152015-10-22 14:00:28 -04002196 T *dest = target + (i * 4);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002197 const T *source = v + (i * components);
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04002198 memcpy(dest, source, components * sizeof(T));
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002199 }
2200 }
Jamie Madill134f93d2017-08-31 17:11:00 -04002201 else if (targetUniform->type == uniformTypeInfo.boolVectorType)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002202 {
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04002203 GLint *boolParams = reinterpret_cast<GLint *>(targetData) + arrayElement * 4;
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002204
Jamie Madill134f93d2017-08-31 17:11:00 -04002205 for (GLint i = 0; i < count; i++)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002206 {
Jamie Madill334d6152015-10-22 14:00:28 -04002207 GLint *dest = boolParams + (i * 4);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002208 const T *source = v + (i * components);
2209
2210 for (int c = 0; c < components; c++)
2211 {
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04002212 dest[c] = (source[c] == static_cast<T>(0)) ? GL_FALSE : GL_TRUE;
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002213 }
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002214 }
Brandon Jones18bd4102014-09-22 14:21:44 -07002215 }
Jamie Madill334d6152015-10-22 14:00:28 -04002216 else
2217 UNREACHABLE();
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002218}
2219
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04002220template <typename T>
2221void ProgramD3D::setUniformInternal(GLint location,
2222 GLsizei count,
2223 const T *v,
Jamie Madill134f93d2017-08-31 17:11:00 -04002224 const gl::UniformTypeInfo &uniformTypeInfo)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002225{
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04002226 const gl::VariableLocation &locationInfo = mState.getUniformLocations()[location];
2227 D3DUniform *targetUniform = mD3DUniforms[locationInfo.index];
2228
Jamie Madill561ed3a2017-08-31 16:48:09 -04002229 mUniformsDirty = true;
2230
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04002231 if (!targetUniform->mSamplerData.empty())
2232 {
Jamie Madill134f93d2017-08-31 17:11:00 -04002233 ASSERT(uniformTypeInfo.type == GL_INT);
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04002234 memcpy(&targetUniform->mSamplerData[locationInfo.element], v, count * sizeof(T));
2235 mDirtySamplerMapping = true;
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04002236 return;
2237 }
2238
2239 if (targetUniform->vsData)
2240 {
Jamie Madill134f93d2017-08-31 17:11:00 -04002241 setUniformImpl(locationInfo, count, v, targetUniform->vsData, uniformTypeInfo);
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04002242 }
2243
2244 if (targetUniform->psData)
2245 {
Jamie Madill134f93d2017-08-31 17:11:00 -04002246 setUniformImpl(locationInfo, count, v, targetUniform->psData, uniformTypeInfo);
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04002247 }
2248
2249 if (targetUniform->csData)
2250 {
Jamie Madill134f93d2017-08-31 17:11:00 -04002251 setUniformImpl(locationInfo, count, v, targetUniform->csData, uniformTypeInfo);
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04002252 }
2253}
2254
2255template <int cols, int rows>
2256void ProgramD3D::setUniformMatrixfvImpl(GLint location,
2257 GLsizei countIn,
2258 GLboolean transpose,
2259 const GLfloat *value,
2260 uint8_t *targetData,
2261 GLenum targetUniformType)
2262{
Jamie Madill62d31cb2015-09-11 13:25:51 -04002263 D3DUniform *targetUniform = getD3DUniformFromLocation(location);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002264
Jamie Madill62d31cb2015-09-11 13:25:51 -04002265 unsigned int elementCount = targetUniform->elementCount();
Jamie Madill48ef11b2016-04-27 15:21:52 -04002266 unsigned int arrayElement = mState.getUniformLocations()[location].element;
Jamie Madill62d31cb2015-09-11 13:25:51 -04002267 unsigned int count = std::min(elementCount - arrayElement, static_cast<unsigned int>(countIn));
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002268
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002269 const unsigned int targetMatrixStride = (4 * rows);
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04002270 GLfloat *target = reinterpret_cast<GLfloat *>(targetData + arrayElement * sizeof(GLfloat) *
2271 targetMatrixStride);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002272
Jamie Madill62d31cb2015-09-11 13:25:51 -04002273 for (unsigned int i = 0; i < count; i++)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002274 {
2275 // Internally store matrices as transposed versions to accomodate HLSL matrix indexing
2276 if (transpose == GL_FALSE)
2277 {
Jamie Madill561ed3a2017-08-31 16:48:09 -04002278 TransposeExpandMatrix<GLfloat, cols, rows>(target, value);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002279 }
2280 else
2281 {
Jamie Madill561ed3a2017-08-31 16:48:09 -04002282 ExpandMatrix<GLfloat, cols, rows>(target, value);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002283 }
2284 target += targetMatrixStride;
2285 value += cols * rows;
2286 }
Jamie Madill561ed3a2017-08-31 16:48:09 -04002287
2288 mUniformsDirty = true;
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002289}
2290
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04002291template <int cols, int rows>
2292void ProgramD3D::setUniformMatrixfvInternal(GLint location,
2293 GLsizei countIn,
2294 GLboolean transpose,
2295 const GLfloat *value,
2296 GLenum targetUniformType)
2297{
2298 D3DUniform *targetUniform = getD3DUniformFromLocation(location);
2299
2300 if (targetUniform->vsData)
2301 {
2302 setUniformMatrixfvImpl<cols, rows>(location, countIn, transpose, value,
2303 targetUniform->vsData, targetUniformType);
2304 }
2305
2306 if (targetUniform->psData)
2307 {
2308 setUniformMatrixfvImpl<cols, rows>(location, countIn, transpose, value,
2309 targetUniform->psData, targetUniformType);
2310 }
2311
2312 if (targetUniform->csData)
2313 {
2314 setUniformMatrixfvImpl<cols, rows>(location, countIn, transpose, value,
2315 targetUniform->csData, targetUniformType);
2316 }
2317}
2318
Jamie Madill4a3c2342015-10-08 12:58:45 -04002319size_t ProgramD3D::getUniformBlockInfo(const sh::InterfaceBlock &interfaceBlock)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002320{
Jamie Madill62d31cb2015-09-11 13:25:51 -04002321 ASSERT(interfaceBlock.staticUse || interfaceBlock.layout != sh::BLOCKLAYOUT_PACKED);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002322
Jamie Madill62d31cb2015-09-11 13:25:51 -04002323 // define member uniforms
2324 sh::Std140BlockEncoder std140Encoder;
Jamie Madillcc2ed612017-03-14 15:59:00 -04002325 sh::HLSLBlockEncoder hlslEncoder(sh::HLSLBlockEncoder::ENCODE_PACKED, false);
Jamie Madill62d31cb2015-09-11 13:25:51 -04002326 sh::BlockLayoutEncoder *encoder = nullptr;
2327
2328 if (interfaceBlock.layout == sh::BLOCKLAYOUT_STANDARD)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002329 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04002330 encoder = &std140Encoder;
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002331 }
2332 else
2333 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04002334 encoder = &hlslEncoder;
Jamie Madill61b8dd92015-09-09 19:04:04 +00002335 }
Jamie Madill62d31cb2015-09-11 13:25:51 -04002336
Jamie Madill39046162016-02-08 15:05:17 -05002337 GetUniformBlockInfo(interfaceBlock.fields, interfaceBlock.fieldPrefix(), encoder,
2338 interfaceBlock.isRowMajorLayout, &mBlockInfo);
Jamie Madill62d31cb2015-09-11 13:25:51 -04002339
2340 return encoder->getBlockSize();
Jamie Madill61b8dd92015-09-09 19:04:04 +00002341}
2342
Jamie Madill62d31cb2015-09-11 13:25:51 -04002343void ProgramD3D::assignAllSamplerRegisters()
Jamie Madilla2eb02c2015-09-11 12:31:41 +00002344{
Olli Etuaho96963162016-03-21 11:54:33 +02002345 for (D3DUniform *d3dUniform : mD3DUniforms)
Jamie Madilla2eb02c2015-09-11 12:31:41 +00002346 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04002347 if (d3dUniform->isSampler())
Jamie Madillfb536032015-09-11 13:19:49 -04002348 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04002349 assignSamplerRegisters(d3dUniform);
Jamie Madillfb536032015-09-11 13:19:49 -04002350 }
Jamie Madilla2eb02c2015-09-11 12:31:41 +00002351 }
2352}
2353
Olli Etuaho96963162016-03-21 11:54:33 +02002354void ProgramD3D::assignSamplerRegisters(D3DUniform *d3dUniform)
Jamie Madillfb536032015-09-11 13:19:49 -04002355{
Jamie Madill62d31cb2015-09-11 13:25:51 -04002356 ASSERT(d3dUniform->isSampler());
Xinghua Caob1239382016-12-13 15:07:05 +08002357 const gl::Shader *computeShader = mState.getAttachedComputeShader();
2358 if (computeShader)
Jamie Madillfb536032015-09-11 13:19:49 -04002359 {
Xinghua Caob1239382016-12-13 15:07:05 +08002360 const ShaderD3D *computeShaderD3D = GetImplAs<ShaderD3D>(mState.getAttachedComputeShader());
2361 ASSERT(computeShaderD3D->hasUniform(d3dUniform));
2362 d3dUniform->csRegisterIndex = computeShaderD3D->getUniformRegister(d3dUniform->name);
2363 ASSERT(d3dUniform->csRegisterIndex != GL_INVALID_INDEX);
2364 AssignSamplers(d3dUniform->csRegisterIndex, d3dUniform->type, d3dUniform->arraySize,
2365 mSamplersCS, &mUsedComputeSamplerRange);
Jamie Madillfb536032015-09-11 13:19:49 -04002366 }
Xinghua Caob1239382016-12-13 15:07:05 +08002367 else
Jamie Madillfb536032015-09-11 13:19:49 -04002368 {
Xinghua Caob1239382016-12-13 15:07:05 +08002369 const ShaderD3D *vertexShaderD3D = GetImplAs<ShaderD3D>(mState.getAttachedVertexShader());
2370 const ShaderD3D *fragmentShaderD3D =
2371 GetImplAs<ShaderD3D>(mState.getAttachedFragmentShader());
2372 ASSERT(vertexShaderD3D->hasUniform(d3dUniform) ||
2373 fragmentShaderD3D->hasUniform(d3dUniform));
2374 if (vertexShaderD3D->hasUniform(d3dUniform))
2375 {
2376 d3dUniform->vsRegisterIndex = vertexShaderD3D->getUniformRegister(d3dUniform->name);
2377 ASSERT(d3dUniform->vsRegisterIndex != GL_INVALID_INDEX);
2378 AssignSamplers(d3dUniform->vsRegisterIndex, d3dUniform->type, d3dUniform->arraySize,
2379 mSamplersVS, &mUsedVertexSamplerRange);
2380 }
2381 if (fragmentShaderD3D->hasUniform(d3dUniform))
2382 {
2383 d3dUniform->psRegisterIndex = fragmentShaderD3D->getUniformRegister(d3dUniform->name);
2384 ASSERT(d3dUniform->psRegisterIndex != GL_INVALID_INDEX);
2385 AssignSamplers(d3dUniform->psRegisterIndex, d3dUniform->type, d3dUniform->arraySize,
2386 mSamplersPS, &mUsedPixelSamplerRange);
2387 }
Jamie Madillfb536032015-09-11 13:19:49 -04002388 }
2389}
2390
Jamie Madill62d31cb2015-09-11 13:25:51 -04002391// static
2392void ProgramD3D::AssignSamplers(unsigned int startSamplerIndex,
Jamie Madilld3dfda22015-07-06 08:28:49 -04002393 GLenum samplerType,
2394 unsigned int samplerCount,
2395 std::vector<Sampler> &outSamplers,
2396 GLuint *outUsedRange)
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002397{
2398 unsigned int samplerIndex = startSamplerIndex;
2399
2400 do
2401 {
Jamie Madill62d31cb2015-09-11 13:25:51 -04002402 ASSERT(samplerIndex < outSamplers.size());
2403 Sampler *sampler = &outSamplers[samplerIndex];
2404 sampler->active = true;
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002405 sampler->textureType = gl::SamplerTypeToTextureType(samplerType);
Jamie Madill62d31cb2015-09-11 13:25:51 -04002406 sampler->logicalTextureUnit = 0;
2407 *outUsedRange = std::max(samplerIndex + 1, *outUsedRange);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002408 samplerIndex++;
2409 } while (samplerIndex < startSamplerIndex + samplerCount);
Brandon Jones18bd4102014-09-22 14:21:44 -07002410}
2411
Brandon Jonesc9610c52014-08-25 17:02:59 -07002412void ProgramD3D::reset()
2413{
Xinghua Caob1239382016-12-13 15:07:05 +08002414 mVertexExecutables.clear();
2415 mPixelExecutables.clear();
Jamie Madill4e31ad52015-10-29 10:32:57 -04002416
Xinghua Caob1239382016-12-13 15:07:05 +08002417 for (auto &geometryExecutable : mGeometryExecutables)
Jamie Madill4e31ad52015-10-29 10:32:57 -04002418 {
Xinghua Caob1239382016-12-13 15:07:05 +08002419 geometryExecutable.reset(nullptr);
Jamie Madill4e31ad52015-10-29 10:32:57 -04002420 }
Brandon Joneseb994362014-09-24 10:27:28 -07002421
Xinghua Caob1239382016-12-13 15:07:05 +08002422 mComputeExecutable.reset(nullptr);
2423
Brandon Jones22502d52014-08-29 16:58:36 -07002424 mVertexHLSL.clear();
Jamie Madill408293f2016-12-20 10:11:45 -05002425 mVertexWorkarounds = angle::CompilerWorkaroundsD3D();
Brandon Jones22502d52014-08-29 16:58:36 -07002426
2427 mPixelHLSL.clear();
Jamie Madill408293f2016-12-20 10:11:45 -05002428 mPixelWorkarounds = angle::CompilerWorkaroundsD3D();
Brandon Jones22502d52014-08-29 16:58:36 -07002429 mUsesFragDepth = false;
Martin Radev41ac68e2017-06-06 12:16:58 +03002430 mHasANGLEMultiviewEnabled = false;
2431 mUsesViewID = false;
Brandon Jones22502d52014-08-29 16:58:36 -07002432 mPixelShaderKey.clear();
Brandon Jones44151a92014-09-10 11:32:25 -07002433 mUsesPointSize = false;
Jamie Madill3e14e2b2015-10-29 14:38:53 -04002434 mUsesFlatInterpolation = false;
Brandon Jones22502d52014-08-29 16:58:36 -07002435
Jamie Madill62d31cb2015-09-11 13:25:51 -04002436 SafeDeleteContainer(mD3DUniforms);
Jamie Madill4a3c2342015-10-08 12:58:45 -04002437 mD3DUniformBlocks.clear();
Jamie Madill62d31cb2015-09-11 13:25:51 -04002438
Xinghua Caob1239382016-12-13 15:07:05 +08002439 mVertexUniformStorage.reset(nullptr);
2440 mFragmentUniformStorage.reset(nullptr);
2441 mComputeUniformStorage.reset(nullptr);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002442
2443 mSamplersPS.clear();
2444 mSamplersVS.clear();
Xinghua Caob1239382016-12-13 15:07:05 +08002445 mSamplersCS.clear();
Brandon Jones1a8a7e32014-10-01 12:49:30 -07002446
2447 mUsedVertexSamplerRange = 0;
Jamie Madill334d6152015-10-22 14:00:28 -04002448 mUsedPixelSamplerRange = 0;
Xinghua Caob1239382016-12-13 15:07:05 +08002449 mUsedComputeSamplerRange = 0;
Jamie Madill334d6152015-10-22 14:00:28 -04002450 mDirtySamplerMapping = true;
Jamie Madill437d2662014-12-05 14:23:35 -05002451
Jamie Madill8047c0d2016-03-07 13:02:12 -05002452 mAttribLocationToD3DSemantic.fill(-1);
Jamie Madillccdf74b2015-08-18 10:46:12 -04002453
Jamie Madill9fc36822015-11-18 13:08:07 -05002454 mStreamOutVaryings.clear();
Jamie Madill4e31ad52015-10-29 10:32:57 -04002455
2456 mGeometryShaderPreamble.clear();
Jamie Madill561ed3a2017-08-31 16:48:09 -04002457
2458 mUniformsDirty = true;
Brandon Jonesc9610c52014-08-25 17:02:59 -07002459}
2460
Geoff Lang7dd2e102014-11-10 15:19:26 -05002461unsigned int ProgramD3D::getSerial() const
2462{
2463 return mSerial;
2464}
2465
2466unsigned int ProgramD3D::issueSerial()
2467{
2468 return mCurrentSerial++;
2469}
2470
Jamie Madillbd044ed2017-06-05 12:59:21 -04002471void ProgramD3D::initAttribLocationsToD3DSemantic(const gl::Context *context)
Jamie Madill63805b42015-08-25 13:17:39 -04002472{
Jamie Madillbd044ed2017-06-05 12:59:21 -04002473 gl::Shader *vertexShader = mState.getAttachedVertexShader();
Jamie Madill63805b42015-08-25 13:17:39 -04002474 ASSERT(vertexShader != nullptr);
2475
2476 // Init semantic index
Jamie Madill34ca4f52017-06-13 11:49:39 -04002477 int semanticIndex = 0;
2478 for (const sh::Attribute &attribute : vertexShader->getActiveAttributes(context))
Jamie Madill63805b42015-08-25 13:17:39 -04002479 {
Jamie Madill8047c0d2016-03-07 13:02:12 -05002480 int regCount = gl::VariableRegisterCount(attribute.type);
Jamie Madill34ca4f52017-06-13 11:49:39 -04002481 GLuint location = mState.getAttributeLocation(attribute.name);
2482 ASSERT(location != std::numeric_limits<GLuint>::max());
Jamie Madill63805b42015-08-25 13:17:39 -04002483
Jamie Madill8047c0d2016-03-07 13:02:12 -05002484 for (int reg = 0; reg < regCount; ++reg)
Jamie Madill63805b42015-08-25 13:17:39 -04002485 {
Jamie Madill34ca4f52017-06-13 11:49:39 -04002486 mAttribLocationToD3DSemantic[location + reg] = semanticIndex++;
Jamie Madill63805b42015-08-25 13:17:39 -04002487 }
2488 }
Jamie Madill437d2662014-12-05 14:23:35 -05002489}
2490
Jamie Madilla779b612017-07-24 11:46:05 -04002491void ProgramD3D::updateCachedInputLayout(Serial associatedSerial, const gl::State &state)
Jamie Madilld3dfda22015-07-06 08:28:49 -04002492{
Jamie Madilla779b612017-07-24 11:46:05 -04002493 if (mCurrentVertexArrayStateSerial == associatedSerial)
2494 {
2495 return;
2496 }
2497
2498 mCurrentVertexArrayStateSerial = associatedSerial;
Jamie Madillbd136f92015-08-10 14:51:37 -04002499 mCachedInputLayout.clear();
Jamie Madilld3dfda22015-07-06 08:28:49 -04002500 const auto &vertexAttributes = state.getVertexArray()->getVertexAttributes();
Jamie Madillf8dd7b12015-08-05 13:50:08 -04002501
Jamie Madill6de51852017-04-12 09:53:01 -04002502 for (size_t locationIndex : mState.getActiveAttribLocationsMask())
Jamie Madilld3dfda22015-07-06 08:28:49 -04002503 {
Jamie Madill8047c0d2016-03-07 13:02:12 -05002504 int d3dSemantic = mAttribLocationToD3DSemantic[locationIndex];
Jamie Madilld3dfda22015-07-06 08:28:49 -04002505
Jamie Madill8047c0d2016-03-07 13:02:12 -05002506 if (d3dSemantic != -1)
Jamie Madilld3dfda22015-07-06 08:28:49 -04002507 {
Jamie Madill8047c0d2016-03-07 13:02:12 -05002508 if (mCachedInputLayout.size() < static_cast<size_t>(d3dSemantic + 1))
Jamie Madillbd136f92015-08-10 14:51:37 -04002509 {
Jamie Madill8047c0d2016-03-07 13:02:12 -05002510 mCachedInputLayout.resize(d3dSemantic + 1, gl::VERTEX_FORMAT_INVALID);
Jamie Madillbd136f92015-08-10 14:51:37 -04002511 }
Jamie Madill8047c0d2016-03-07 13:02:12 -05002512 mCachedInputLayout[d3dSemantic] =
2513 GetVertexFormatType(vertexAttributes[locationIndex],
2514 state.getVertexAttribCurrentValue(locationIndex).Type);
Jamie Madilld3dfda22015-07-06 08:28:49 -04002515 }
2516 }
Jamie Madill4c19a8a2017-07-24 11:46:06 -04002517
2518 VertexExecutable::getSignature(mRenderer, mCachedInputLayout, &mCachedVertexSignature);
2519}
2520
2521void ProgramD3D::updateCachedOutputLayout(const gl::Context *context,
2522 const gl::Framebuffer *framebuffer)
2523{
2524 GetPixelOutputLayoutFromFramebuffer(context, framebuffer, &mPixelShaderOutputLayoutCache);
Jamie Madilld3dfda22015-07-06 08:28:49 -04002525}
2526
Jamie Madill192745a2016-12-22 15:58:21 -05002527void ProgramD3D::gatherTransformFeedbackVaryings(const gl::VaryingPacking &varyingPacking,
2528 const BuiltinInfo &builtins)
Jamie Madillccdf74b2015-08-18 10:46:12 -04002529{
Jamie Madill9fc36822015-11-18 13:08:07 -05002530 const std::string &varyingSemantic =
2531 GetVaryingSemantic(mRenderer->getMajorShaderModel(), usesPointSize());
2532
Jamie Madillccdf74b2015-08-18 10:46:12 -04002533 // Gather the linked varyings that are used for transform feedback, they should all exist.
Jamie Madill9fc36822015-11-18 13:08:07 -05002534 mStreamOutVaryings.clear();
2535
Jamie Madill48ef11b2016-04-27 15:21:52 -04002536 const auto &tfVaryingNames = mState.getTransformFeedbackVaryingNames();
Jamie Madill9fc36822015-11-18 13:08:07 -05002537 for (unsigned int outputSlot = 0; outputSlot < static_cast<unsigned int>(tfVaryingNames.size());
2538 ++outputSlot)
Jamie Madillccdf74b2015-08-18 10:46:12 -04002539 {
Jamie Madill9fc36822015-11-18 13:08:07 -05002540 const auto &tfVaryingName = tfVaryingNames[outputSlot];
2541 if (tfVaryingName == "gl_Position")
Jamie Madillccdf74b2015-08-18 10:46:12 -04002542 {
Jamie Madill9fc36822015-11-18 13:08:07 -05002543 if (builtins.glPosition.enabled)
Jamie Madillccdf74b2015-08-18 10:46:12 -04002544 {
Jamie Madill9fc36822015-11-18 13:08:07 -05002545 mStreamOutVaryings.push_back(D3DVarying(builtins.glPosition.semantic,
2546 builtins.glPosition.index, 4, outputSlot));
2547 }
2548 }
2549 else if (tfVaryingName == "gl_FragCoord")
2550 {
2551 if (builtins.glFragCoord.enabled)
2552 {
2553 mStreamOutVaryings.push_back(D3DVarying(builtins.glFragCoord.semantic,
2554 builtins.glFragCoord.index, 4, outputSlot));
2555 }
2556 }
2557 else if (tfVaryingName == "gl_PointSize")
2558 {
2559 if (builtins.glPointSize.enabled)
2560 {
2561 mStreamOutVaryings.push_back(D3DVarying("PSIZE", 0, 1, outputSlot));
2562 }
2563 }
2564 else
2565 {
jchen10a9042d32017-03-17 08:50:45 +08002566 size_t subscript = GL_INVALID_INDEX;
2567 std::string baseName = gl::ParseResourceName(tfVaryingName, &subscript);
Jamie Madill192745a2016-12-22 15:58:21 -05002568 for (const auto &registerInfo : varyingPacking.getRegisterList())
Jamie Madill9fc36822015-11-18 13:08:07 -05002569 {
Jamie Madill55c25d02015-11-18 13:08:08 -05002570 const auto &varying = *registerInfo.packedVarying->varying;
2571 GLenum transposedType = gl::TransposeMatrixType(varying.type);
Jamie Madill9fc36822015-11-18 13:08:07 -05002572 int componentCount = gl::VariableColumnCount(transposedType);
2573 ASSERT(!varying.isBuiltIn());
2574
Jamie Madill55c25d02015-11-18 13:08:08 -05002575 // Transform feedback for varying structs is underspecified.
2576 // See Khronos bug 9856.
2577 // TODO(jmadill): Figure out how to be spec-compliant here.
2578 if (registerInfo.packedVarying->isStructField() || varying.isStruct())
2579 continue;
2580
Jamie Madill9fc36822015-11-18 13:08:07 -05002581 // There can be more than one register assigned to a particular varying, and each
2582 // register needs its own stream out entry.
jchen10a9042d32017-03-17 08:50:45 +08002583 if (baseName == registerInfo.packedVarying->varying->name &&
2584 (subscript == GL_INVALID_INDEX || subscript == registerInfo.varyingArrayIndex))
Jamie Madill9fc36822015-11-18 13:08:07 -05002585 {
2586 mStreamOutVaryings.push_back(D3DVarying(
2587 varyingSemantic, registerInfo.semanticIndex, componentCount, outputSlot));
2588 }
Jamie Madillccdf74b2015-08-18 10:46:12 -04002589 }
2590 }
2591 }
2592}
Jamie Madill62d31cb2015-09-11 13:25:51 -04002593
2594D3DUniform *ProgramD3D::getD3DUniformFromLocation(GLint location)
2595{
Jamie Madill48ef11b2016-04-27 15:21:52 -04002596 return mD3DUniforms[mState.getUniformLocations()[location].index];
Jamie Madill62d31cb2015-09-11 13:25:51 -04002597}
Jamie Madill4a3c2342015-10-08 12:58:45 -04002598
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04002599const D3DUniform *ProgramD3D::getD3DUniformFromLocation(GLint location) const
2600{
2601 return mD3DUniforms[mState.getUniformLocations()[location].index];
2602}
2603
Olli Etuaho855d9642017-05-17 14:05:06 +03002604bool ProgramD3D::getUniformBlockSize(const std::string &blockName,
2605 const std::string & /* blockMappedName */,
2606 size_t *sizeOut) const
Jamie Madill4a3c2342015-10-08 12:58:45 -04002607{
2608 std::string baseName = blockName;
2609 gl::ParseAndStripArrayIndex(&baseName);
2610
2611 auto sizeIter = mBlockDataSizes.find(baseName);
2612 if (sizeIter == mBlockDataSizes.end())
2613 {
2614 *sizeOut = 0;
2615 return false;
2616 }
2617
2618 *sizeOut = sizeIter->second;
2619 return true;
2620}
2621
2622bool ProgramD3D::getUniformBlockMemberInfo(const std::string &memberUniformName,
Olli Etuaho855d9642017-05-17 14:05:06 +03002623 const std::string & /* memberUniformMappedName */,
Jamie Madill4a3c2342015-10-08 12:58:45 -04002624 sh::BlockMemberInfo *memberInfoOut) const
2625{
2626 auto infoIter = mBlockInfo.find(memberUniformName);
2627 if (infoIter == mBlockInfo.end())
2628 {
2629 *memberInfoOut = sh::BlockMemberInfo::getDefaultBlockInfo();
2630 return false;
2631 }
2632
2633 *memberInfoOut = infoIter->second;
2634 return true;
2635}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002636
2637void ProgramD3D::setPathFragmentInputGen(const std::string &inputName,
2638 GLenum genMode,
2639 GLint components,
2640 const GLfloat *coeffs)
2641{
2642 UNREACHABLE();
2643}
2644
Jamie Madill4c19a8a2017-07-24 11:46:06 -04002645bool ProgramD3D::hasVertexExecutableForCachedInputLayout()
2646{
2647 VertexExecutable::getSignature(mRenderer, mCachedInputLayout, &mCachedVertexSignature);
2648
2649 for (size_t executableIndex = 0; executableIndex < mVertexExecutables.size(); executableIndex++)
2650 {
2651 if (mVertexExecutables[executableIndex]->matchesSignature(mCachedVertexSignature))
2652 {
2653 return true;
2654 }
2655 }
2656
2657 return false;
2658}
2659
2660bool ProgramD3D::hasGeometryExecutableForPrimitiveType(GLenum drawMode)
2661{
2662 if (!usesGeometryShader(drawMode))
2663 {
2664 // No shader necessary mean we have the required (null) executable.
2665 return true;
2666 }
2667
2668 gl::PrimitiveType geometryShaderType = GetGeometryShaderTypeFromDrawMode(drawMode);
2669 return mGeometryExecutables[geometryShaderType].get() != nullptr;
2670}
2671
2672bool ProgramD3D::hasPixelExecutableForCachedOutputLayout()
2673{
2674 for (size_t executableIndex = 0; executableIndex < mPixelExecutables.size(); executableIndex++)
2675 {
2676 if (mPixelExecutables[executableIndex]->matchesSignature(mPixelShaderOutputLayoutCache))
2677 {
2678 return true;
2679 }
2680 }
2681
2682 return false;
2683}
2684
Jamie Madill54164b02017-08-28 15:17:37 -04002685template <typename DestT>
2686void ProgramD3D::getUniformInternal(GLint location, DestT *dataOut) const
2687{
2688 const gl::VariableLocation &locationInfo = mState.getUniformLocations()[location];
2689 const gl::LinkedUniform &uniform = mState.getUniforms()[locationInfo.index];
2690
Jamie Madillbe5e2ec2017-08-31 13:28:28 -04002691 const D3DUniform *targetUniform = getD3DUniformFromLocation(location);
2692 const uint8_t *srcPointer = targetUniform->getDataPtrToElement(locationInfo.element);
2693
2694 if (gl::IsMatrixType(uniform.type))
2695 {
2696 GetMatrixUniform(gl::VariableColumnCount(uniform.type), gl::VariableRowCount(uniform.type),
2697 dataOut, reinterpret_cast<const DestT *>(srcPointer));
2698 }
2699 else
2700 {
2701 memcpy(dataOut, srcPointer, uniform.getElementSize());
2702 }
Jamie Madill54164b02017-08-28 15:17:37 -04002703}
2704
2705void ProgramD3D::getUniformfv(const gl::Context *context, GLint location, GLfloat *params) const
2706{
2707 getUniformInternal(location, params);
2708}
2709
2710void ProgramD3D::getUniformiv(const gl::Context *context, GLint location, GLint *params) const
2711{
2712 getUniformInternal(location, params);
2713}
2714
2715void ProgramD3D::getUniformuiv(const gl::Context *context, GLint location, GLuint *params) const
2716{
2717 getUniformInternal(location, params);
2718}
2719
Jamie Madill8047c0d2016-03-07 13:02:12 -05002720} // namespace rx