blob: 9684320ca42fd9b60ea13c9dc877bee2a3c9b2dd [file] [log] [blame]
Jamie Madill5f562732014-02-14 16:41:24 -05001//
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// DynamicHLSL.cpp: Implementation for link and run-time HLSL generation
7//
8
Geoff Lang2b5420c2014-11-19 14:20:15 -05009#include "libANGLE/renderer/d3d/DynamicHLSL.h"
Jamie Madill9e0478f2015-01-13 11:13:54 -050010
11#include "common/utilities.h"
Daniel Bratell73941de2015-02-25 14:34:49 +010012#include "compiler/translator/blocklayoutHLSL.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050013#include "libANGLE/Program.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050014#include "libANGLE/Shader.h"
15#include "libANGLE/formatutils.h"
Jamie Madill80a6fc02015-08-21 16:53:16 -040016#include "libANGLE/renderer/d3d/RendererD3D.h"
17#include "libANGLE/renderer/d3d/ShaderD3D.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040018
Jamie Madill53cb14d2014-07-08 15:02:35 -040019// For use with ArrayString, see angleutils.h
Geoff Langd4475812015-03-18 10:53:05 -040020static_assert(GL_INVALID_INDEX == UINT_MAX, "GL_INVALID_INDEX must be equal to the max unsigned int.");
Jamie Madill5f562732014-02-14 16:41:24 -050021
Brandon Jonesd8d72432014-08-22 15:11:23 -070022using namespace gl;
23
Jamie Madill30d6c252014-11-13 10:03:33 -050024namespace rx
25{
26
Jamie Madill3f2e61d2014-09-05 10:38:05 -040027namespace
Jamie Madill5f562732014-02-14 16:41:24 -050028{
Jamie Madill8664b062014-02-14 16:41:29 -050029
30std::string HLSLComponentTypeString(GLenum componentType)
31{
32 switch (componentType)
33 {
34 case GL_UNSIGNED_INT: return "uint";
35 case GL_INT: return "int";
36 case GL_UNSIGNED_NORMALIZED:
37 case GL_SIGNED_NORMALIZED:
38 case GL_FLOAT: return "float";
39 default: UNREACHABLE(); return "not-component-type";
40 }
Jamie Madill5f562732014-02-14 16:41:24 -050041}
42
Jamie Madill8664b062014-02-14 16:41:29 -050043std::string HLSLComponentTypeString(GLenum componentType, int componentCount)
44{
45 return HLSLComponentTypeString(componentType) + (componentCount > 1 ? Str(componentCount) : "");
46}
47
48std::string HLSLMatrixTypeString(GLenum type)
49{
50 switch (type)
51 {
52 case GL_FLOAT_MAT2: return "float2x2";
53 case GL_FLOAT_MAT3: return "float3x3";
54 case GL_FLOAT_MAT4: return "float4x4";
55 case GL_FLOAT_MAT2x3: return "float2x3";
56 case GL_FLOAT_MAT3x2: return "float3x2";
57 case GL_FLOAT_MAT2x4: return "float2x4";
58 case GL_FLOAT_MAT4x2: return "float4x2";
59 case GL_FLOAT_MAT3x4: return "float3x4";
60 case GL_FLOAT_MAT4x3: return "float4x3";
61 default: UNREACHABLE(); return "not-matrix-type";
62 }
63}
64
65std::string HLSLTypeString(GLenum type)
66{
67 if (gl::IsMatrixType(type))
68 {
69 return HLSLMatrixTypeString(type);
70 }
71
Jamie Madillf2575982014-06-25 16:04:54 -040072 return HLSLComponentTypeString(gl::VariableComponentType(type), gl::VariableComponentCount(type));
Jamie Madill8664b062014-02-14 16:41:29 -050073}
74
Gregoire Payen de La Garanderiee1728542015-01-07 11:31:54 +000075const PixelShaderOutputVariable *FindOutputAtLocation(const std::vector<PixelShaderOutputVariable> &outputVariables,
Jamie Madill3f2e61d2014-09-05 10:38:05 -040076 unsigned int location)
77{
78 for (size_t variableIndex = 0; variableIndex < outputVariables.size(); ++variableIndex)
79 {
80 if (outputVariables[variableIndex].outputIndex == location)
81 {
Gregoire Payen de La Garanderiee1728542015-01-07 11:31:54 +000082 return &outputVariables[variableIndex];
Jamie Madill3f2e61d2014-09-05 10:38:05 -040083 }
84 }
85
Gregoire Payen de La Garanderiee1728542015-01-07 11:31:54 +000086 return NULL;
Jamie Madill3f2e61d2014-09-05 10:38:05 -040087}
88
Jamie Madill4cff2472015-08-21 16:53:18 -040089typedef const PackedVarying *VaryingPacking[gl::IMPLEMENTATION_MAX_VARYING_VECTORS][4];
Jamie Madillc5ede1a2014-02-14 16:41:27 -050090
Jamie Madill4cff2472015-08-21 16:53:18 -040091bool PackVarying(PackedVarying *packedVarying, const int maxVaryingVectors, VaryingPacking &packing)
Jamie Madill5f562732014-02-14 16:41:24 -050092{
Jamie Madillf4780c12015-02-11 16:33:11 -050093 // Make sure we use transposed matrix types to count registers correctly.
94 int registers = 0;
95 int elements = 0;
Jamie Madill5f562732014-02-14 16:41:24 -050096
Jamie Madill4cff2472015-08-21 16:53:18 -040097 const sh::Varying &varying = *packedVarying->varying;
98
99 if (varying.isStruct())
Jamie Madillf4780c12015-02-11 16:33:11 -0500100 {
Jamie Madill4cff2472015-08-21 16:53:18 -0400101 registers = HLSLVariableRegisterCount(varying, true) * varying.elementCount();
Jamie Madillf4780c12015-02-11 16:33:11 -0500102 elements = 4;
103 }
104 else
105 {
Jamie Madill4cff2472015-08-21 16:53:18 -0400106 GLenum transposedType = TransposeMatrixType(varying.type);
107 registers = VariableRowCount(transposedType) * varying.elementCount();
Jamie Madillf4780c12015-02-11 16:33:11 -0500108 elements = VariableColumnCount(transposedType);
109 }
Jamie Madill5f562732014-02-14 16:41:24 -0500110
Jamie Madillff0d2ba2014-05-14 13:49:10 -0400111 if (elements >= 2 && elements <= 4)
Jamie Madill5f562732014-02-14 16:41:24 -0500112 {
Jamie Madillff0d2ba2014-05-14 13:49:10 -0400113 for (int r = 0; r <= maxVaryingVectors - registers; r++)
Jamie Madill5f562732014-02-14 16:41:24 -0500114 {
Geoff Lang48dcae72014-02-05 16:28:24 -0500115 bool available = true;
116
117 for (int y = 0; y < registers && available; y++)
118 {
119 for (int x = 0; x < elements && available; x++)
120 {
121 if (packing[r + y][x])
122 {
123 available = false;
124 }
125 }
126 }
127
128 if (available)
129 {
Jamie Madill4cff2472015-08-21 16:53:18 -0400130 packedVarying->registerIndex = r;
131 packedVarying->columnIndex = 0;
Geoff Lang48dcae72014-02-05 16:28:24 -0500132
133 for (int y = 0; y < registers; y++)
134 {
135 for (int x = 0; x < elements; x++)
136 {
Jamie Madill4cff2472015-08-21 16:53:18 -0400137 packing[r + y][x] = packedVarying;
Geoff Lang48dcae72014-02-05 16:28:24 -0500138 }
139 }
140
Jamie Madillff0d2ba2014-05-14 13:49:10 -0400141 return true;
Geoff Lang48dcae72014-02-05 16:28:24 -0500142 }
143 }
144
Jamie Madillff0d2ba2014-05-14 13:49:10 -0400145 if (elements == 2)
Geoff Lang48dcae72014-02-05 16:28:24 -0500146 {
Jamie Madillff0d2ba2014-05-14 13:49:10 -0400147 for (int r = maxVaryingVectors - registers; r >= 0; r--)
Jamie Madill5f562732014-02-14 16:41:24 -0500148 {
149 bool available = true;
150
151 for (int y = 0; y < registers && available; y++)
152 {
Geoff Lang48dcae72014-02-05 16:28:24 -0500153 for (int x = 2; x < 4 && available; x++)
Jamie Madill5f562732014-02-14 16:41:24 -0500154 {
155 if (packing[r + y][x])
156 {
157 available = false;
158 }
159 }
160 }
161
162 if (available)
163 {
Jamie Madill4cff2472015-08-21 16:53:18 -0400164 packedVarying->registerIndex = r;
165 packedVarying->columnIndex = 2;
Jamie Madill5f562732014-02-14 16:41:24 -0500166
167 for (int y = 0; y < registers; y++)
168 {
Geoff Lang48dcae72014-02-05 16:28:24 -0500169 for (int x = 2; x < 4; x++)
Jamie Madill5f562732014-02-14 16:41:24 -0500170 {
Jamie Madill4cff2472015-08-21 16:53:18 -0400171 packing[r + y][x] = packedVarying;
Jamie Madill5f562732014-02-14 16:41:24 -0500172 }
173 }
174
Jamie Madillff0d2ba2014-05-14 13:49:10 -0400175 return true;
Jamie Madill5f562732014-02-14 16:41:24 -0500176 }
177 }
Jamie Madill5f562732014-02-14 16:41:24 -0500178 }
Geoff Lang48dcae72014-02-05 16:28:24 -0500179 }
180 else if (elements == 1)
181 {
182 int space[4] = { 0 };
183
184 for (int y = 0; y < maxVaryingVectors; y++)
Jamie Madill5f562732014-02-14 16:41:24 -0500185 {
Jamie Madill5f562732014-02-14 16:41:24 -0500186 for (int x = 0; x < 4; x++)
187 {
Geoff Lang48dcae72014-02-05 16:28:24 -0500188 space[x] += packing[y][x] ? 0 : 1;
Jamie Madill5f562732014-02-14 16:41:24 -0500189 }
190 }
Jamie Madill5f562732014-02-14 16:41:24 -0500191
Geoff Lang48dcae72014-02-05 16:28:24 -0500192 int column = 0;
193
194 for (int x = 0; x < 4; x++)
195 {
Austin Kinrossaf875522014-08-25 21:06:07 -0700196 if (space[x] >= registers && (space[column] < registers || space[x] < space[column]))
Geoff Lang48dcae72014-02-05 16:28:24 -0500197 {
198 column = x;
199 }
200 }
201
202 if (space[column] >= registers)
203 {
204 for (int r = 0; r < maxVaryingVectors; r++)
205 {
206 if (!packing[r][column])
207 {
Jamie Madill4cff2472015-08-21 16:53:18 -0400208 packedVarying->registerIndex = r;
209 packedVarying->columnIndex = column;
Geoff Lang48dcae72014-02-05 16:28:24 -0500210
211 for (int y = r; y < r + registers; y++)
212 {
Jamie Madill4cff2472015-08-21 16:53:18 -0400213 packing[y][column] = packedVarying;
Geoff Lang48dcae72014-02-05 16:28:24 -0500214 }
215
216 break;
217 }
218 }
219
Jamie Madillff0d2ba2014-05-14 13:49:10 -0400220 return true;
Geoff Lang48dcae72014-02-05 16:28:24 -0500221 }
222 }
223 else UNREACHABLE();
224
Jamie Madillff0d2ba2014-05-14 13:49:10 -0400225 return false;
Geoff Lang48dcae72014-02-05 16:28:24 -0500226}
227
Jamie Madill4cff2472015-08-21 16:53:18 -0400228const std::string VERTEX_ATTRIBUTE_STUB_STRING = "@@ VERTEX ATTRIBUTES @@";
229const std::string PIXEL_OUTPUT_STUB_STRING = "@@ PIXEL OUTPUT @@";
230}
231
232DynamicHLSL::DynamicHLSL(RendererD3D *const renderer) : mRenderer(renderer)
233{
234}
235
Geoff Lang48dcae72014-02-05 16:28:24 -0500236// Packs varyings into generic varying registers, using the algorithm from [OpenGL ES Shading Language 1.00 rev. 17] appendix A section 7 page 111
237// Returns the number of used varying registers, or -1 if unsuccesful
Jamie Madill4cff2472015-08-21 16:53:18 -0400238int DynamicHLSL::packVaryings(InfoLog &infoLog,
Jamie Madillca03b352015-09-02 12:38:13 -0400239 std::vector<PackedVarying> *packedVaryings,
Jamie Madill4cff2472015-08-21 16:53:18 -0400240 const std::vector<std::string> &transformFeedbackVaryings)
Geoff Lang48dcae72014-02-05 16:28:24 -0500241{
Geoff Lang3a61c322014-07-10 13:01:54 -0400242 // TODO (geofflang): Use context's caps
243 const int maxVaryingVectors = mRenderer->getRendererCaps().maxVaryingVectors;
Geoff Lang48dcae72014-02-05 16:28:24 -0500244
Jamie Madill4cff2472015-08-21 16:53:18 -0400245 VaryingPacking packing = {};
246
Jamie Madillca03b352015-09-02 12:38:13 -0400247 std::set<std::string> uniqueVaryingNames;
Geoff Lang48dcae72014-02-05 16:28:24 -0500248
Jamie Madillca03b352015-09-02 12:38:13 -0400249 for (PackedVarying &packedVarying : *packedVaryings)
Geoff Lang48dcae72014-02-05 16:28:24 -0500250 {
Jamie Madillca03b352015-09-02 12:38:13 -0400251 const sh::Varying &varying = *packedVarying.varying;
Jamie Madill54ad4f82014-09-03 09:40:46 -0400252
253 // Do not assign registers to built-in or unreferenced varyings
Jamie Madill4cff2472015-08-21 16:53:18 -0400254 if (varying.isBuiltIn() || !varying.staticUse)
Jamie Madill54ad4f82014-09-03 09:40:46 -0400255 {
256 continue;
257 }
258
Jamie Madillca03b352015-09-02 12:38:13 -0400259 ASSERT(uniqueVaryingNames.count(varying.name) == 0);
260
261 if (PackVarying(&packedVarying, maxVaryingVectors, packing))
Geoff Lang48dcae72014-02-05 16:28:24 -0500262 {
Jamie Madillca03b352015-09-02 12:38:13 -0400263 uniqueVaryingNames.insert(varying.name);
Geoff Lang48dcae72014-02-05 16:28:24 -0500264 }
265 else
Jamie Madill5f562732014-02-14 16:41:24 -0500266 {
Jamie Madill4cff2472015-08-21 16:53:18 -0400267 infoLog << "Could not pack varying " << varying.name;
Jamie Madill5f562732014-02-14 16:41:24 -0500268 return -1;
269 }
270 }
271
Jamie Madillca03b352015-09-02 12:38:13 -0400272 for (const std::string &transformFeedbackVaryingName : transformFeedbackVaryings)
Geoff Lang48dcae72014-02-05 16:28:24 -0500273 {
Jamie Madillca03b352015-09-02 12:38:13 -0400274 if (transformFeedbackVaryingName == "gl_Position" ||
275 transformFeedbackVaryingName == "gl_PointSize")
Jamie Madill55d611e2014-10-24 16:28:14 -0400276 {
277 // do not pack builtin XFB varyings
278 continue;
279 }
280
Jamie Madillca03b352015-09-02 12:38:13 -0400281 if (uniqueVaryingNames.count(transformFeedbackVaryingName) == 0)
Geoff Lang48dcae72014-02-05 16:28:24 -0500282 {
283 bool found = false;
Jamie Madillca03b352015-09-02 12:38:13 -0400284 for (PackedVarying &packedVarying : *packedVaryings)
Geoff Lang48dcae72014-02-05 16:28:24 -0500285 {
Jamie Madillca03b352015-09-02 12:38:13 -0400286 const sh::Varying &varying = *packedVarying.varying;
287 if (transformFeedbackVaryingName == varying.name)
Geoff Lang48dcae72014-02-05 16:28:24 -0500288 {
Jamie Madillca03b352015-09-02 12:38:13 -0400289 if (!PackVarying(&packedVarying, maxVaryingVectors, packing))
Geoff Lang48dcae72014-02-05 16:28:24 -0500290 {
Jamie Madill4cff2472015-08-21 16:53:18 -0400291 infoLog << "Could not pack varying " << varying.name;
Geoff Lang48dcae72014-02-05 16:28:24 -0500292 return -1;
293 }
294
295 found = true;
296 break;
297 }
298 }
299
Jamie Madill55d611e2014-10-24 16:28:14 -0400300 if (!found)
Geoff Lang48dcae72014-02-05 16:28:24 -0500301 {
Jamie Madillca03b352015-09-02 12:38:13 -0400302 infoLog << "Transform feedback varying " << transformFeedbackVaryingName
Jamie Madillf6113162015-05-07 11:49:21 -0400303 << " does not exist in the vertex shader.";
Geoff Lang48dcae72014-02-05 16:28:24 -0500304 return -1;
305 }
306 }
307 }
308
Jamie Madill5f562732014-02-14 16:41:24 -0500309 // Return the number of used registers
310 int registers = 0;
311
312 for (int r = 0; r < maxVaryingVectors; r++)
313 {
314 if (packing[r][0] || packing[r][1] || packing[r][2] || packing[r][3])
315 {
316 registers++;
317 }
318 }
319
320 return registers;
321}
322
Jamie Madillca03b352015-09-02 12:38:13 -0400323std::string DynamicHLSL::generateVaryingHLSL(const std::vector<PackedVarying> &varyings,
324 bool shaderUsesPointSize) const
Jamie Madill5f562732014-02-14 16:41:24 -0500325{
Jamie Madillca03b352015-09-02 12:38:13 -0400326 std::string varyingSemantic = getVaryingSemantic(shaderUsesPointSize);
Jamie Madill5f562732014-02-14 16:41:24 -0500327 std::string varyingHLSL;
328
Jamie Madill4cff2472015-08-21 16:53:18 -0400329 for (const PackedVarying &packedVarying : varyings)
Jamie Madill5f562732014-02-14 16:41:24 -0500330 {
Jamie Madill4cff2472015-08-21 16:53:18 -0400331 if (!packedVarying.registerAssigned())
Jamie Madill5f562732014-02-14 16:41:24 -0500332 {
Jamie Madill4cff2472015-08-21 16:53:18 -0400333 continue;
334 }
Geoff Lang48dcae72014-02-05 16:28:24 -0500335
Jamie Madill4cff2472015-08-21 16:53:18 -0400336 const sh::Varying &varying = *packedVarying.varying;
337
338 ASSERT(!varying.isBuiltIn());
339 GLenum transposedType = TransposeMatrixType(varying.type);
340 int variableRows = (varying.isStruct() ? 1 : VariableRowCount(transposedType));
341
342 for (unsigned int elementIndex = 0; elementIndex < varying.elementCount(); elementIndex++)
343 {
344 for (int row = 0; row < variableRows; row++)
Jamie Madill5f562732014-02-14 16:41:24 -0500345 {
Jamie Madill4cff2472015-08-21 16:53:18 -0400346 // TODO: Add checks to ensure D3D interpolation modifiers don't result in too many
347 // registers being used.
348 // For example, if there are N registers, and we have N vec3 varyings and 1 float
349 // varying, then D3D will pack them into N registers.
350 // If the float varying has the 'nointerpolation' modifier on it then we would need
351 // N + 1 registers, and D3D compilation will fail.
352
353 switch (varying.interpolation)
Jamie Madill5f562732014-02-14 16:41:24 -0500354 {
Jamie Madill4cff2472015-08-21 16:53:18 -0400355 case sh::INTERPOLATION_SMOOTH:
356 varyingHLSL += " ";
357 break;
358 case sh::INTERPOLATION_FLAT:
359 varyingHLSL += " nointerpolation ";
360 break;
361 case sh::INTERPOLATION_CENTROID:
362 varyingHLSL += " centroid ";
363 break;
364 default:
365 UNREACHABLE();
Jamie Madill5f562732014-02-14 16:41:24 -0500366 }
Jamie Madill4cff2472015-08-21 16:53:18 -0400367
368 unsigned int semanticIndex =
369 elementIndex * variableRows +
370 packedVarying.columnIndex * mRenderer->getRendererCaps().maxVaryingVectors +
371 packedVarying.registerIndex + row;
372 std::string n = Str(semanticIndex);
373
374 std::string typeString;
375
376 if (varying.isStruct())
377 {
378 // TODO(jmadill): pass back translated name from the shader translator
379 typeString = decorateVariable(varying.structName);
380 }
381 else
382 {
383 GLenum componentType = VariableComponentType(transposedType);
384 int columnCount = VariableColumnCount(transposedType);
385 typeString = HLSLComponentTypeString(componentType, columnCount);
386 }
387 varyingHLSL += typeString + " v" + n + " : " + varyingSemantic + n + ";\n";
Jamie Madill5f562732014-02-14 16:41:24 -0500388 }
389 }
Jamie Madill5f562732014-02-14 16:41:24 -0500390 }
391
392 return varyingHLSL;
393}
394
Jamie Madillf2575982014-06-25 16:04:54 -0400395std::string DynamicHLSL::generateVertexShaderForInputLayout(const std::string &sourceShader,
Jamie Madilld3dfda22015-07-06 08:28:49 -0400396 const InputLayout &inputLayout,
Jamie Madill3da79b72015-04-27 11:09:17 -0400397 const std::vector<sh::Attribute> &shaderAttributes) const
Jamie Madillc5ede1a2014-02-14 16:41:27 -0500398{
Jamie Madill3b7e2052014-03-17 09:47:43 -0400399 std::string structHLSL, initHLSL;
Jamie Madillc5ede1a2014-02-14 16:41:27 -0500400
401 int semanticIndex = 0;
Jamie Madill3b7e2052014-03-17 09:47:43 -0400402 unsigned int inputIndex = 0;
403
Cooper Partine6d14cc2015-02-20 12:32:58 -0800404 // If gl_PointSize is used in the shader then pointsprites rendering is expected.
405 // If the renderer does not support Geometry shaders then Instanced PointSprite emulation
406 // must be used.
407 bool usesPointSize = sourceShader.find("GL_USES_POINT_SIZE") != std::string::npos;
408 bool useInstancedPointSpriteEmulation = usesPointSize && mRenderer->getWorkarounds().useInstancedPointSpriteEmulation;
409
410 // Instanced PointSprite emulation requires additional entries in the
411 // VS_INPUT structure to support the vertices that make up the quad vertices.
412 // These values must be in sync with the cooresponding values added during inputlayout creation
413 // in InputLayoutCache::applyVertexBuffers().
414 //
415 // The additional entries must appear first in the VS_INPUT layout because
416 // Windows Phone 8 era devices require per vertex data to physically come
417 // before per instance data in the shader.
418 if (useInstancedPointSpriteEmulation)
419 {
420 structHLSL += " float3 spriteVertexPos : SPRITEPOSITION0;\n";
421 structHLSL += " float2 spriteTexCoord : SPRITETEXCOORD0;\n";
422 }
423
Jamie Madill3da79b72015-04-27 11:09:17 -0400424 for (size_t attributeIndex = 0; attributeIndex < shaderAttributes.size(); ++attributeIndex)
Jamie Madillc5ede1a2014-02-14 16:41:27 -0500425 {
Jamie Madillf2575982014-06-25 16:04:54 -0400426 const sh::Attribute &shaderAttribute = shaderAttributes[attributeIndex];
Jamie Madill8664b062014-02-14 16:41:29 -0500427 if (!shaderAttribute.name.empty())
Jamie Madillc5ede1a2014-02-14 16:41:27 -0500428 {
Geoff Lang5ac5ae82014-09-09 10:14:17 -0400429 ASSERT(inputIndex < MAX_VERTEX_ATTRIBS);
Jamie Madillf8dd7b12015-08-05 13:50:08 -0400430 VertexFormatType vertexFormatType =
431 inputIndex < inputLayout.size() ? inputLayout[inputIndex] : VERTEX_FORMAT_INVALID;
Geoff Lang5ac5ae82014-09-09 10:14:17 -0400432
Jamie Madill3b7e2052014-03-17 09:47:43 -0400433 // HLSL code for input structure
Jamie Madill8664b062014-02-14 16:41:29 -0500434 if (IsMatrixType(shaderAttribute.type))
435 {
436 // Matrix types are always transposed
Jamie Madill3f2e61d2014-09-05 10:38:05 -0400437 structHLSL += " " + HLSLMatrixTypeString(TransposeMatrixType(shaderAttribute.type));
Jamie Madill8664b062014-02-14 16:41:29 -0500438 }
439 else
440 {
Jamie Madilld3dfda22015-07-06 08:28:49 -0400441 GLenum componentType = mRenderer->getVertexComponentType(vertexFormatType);
Gregoire Payen de La Garanderieb3dced22015-01-12 14:54:55 +0000442
443 if (shaderAttribute.name == "gl_InstanceID")
444 {
445 // The input type of the instance ID in HLSL (uint) differs from the one in ESSL (int).
446 structHLSL += " uint";
447 }
448 else
449 {
450 structHLSL += " " + HLSLComponentTypeString(componentType, VariableComponentCount(shaderAttribute.type));
451 }
Jamie Madill8664b062014-02-14 16:41:29 -0500452 }
Jamie Madillc5ede1a2014-02-14 16:41:27 -0500453
Gregoire Payen de La Garanderieb3dced22015-01-12 14:54:55 +0000454 structHLSL += " " + decorateVariable(shaderAttribute.name) + " : ";
455
456 if (shaderAttribute.name == "gl_InstanceID")
457 {
458 structHLSL += "SV_InstanceID";
459 }
460 else
461 {
462 structHLSL += "TEXCOORD" + Str(semanticIndex);
463 semanticIndex += VariableRegisterCount(shaderAttribute.type);
464 }
465
466 structHLSL += ";\n";
Jamie Madillc5ede1a2014-02-14 16:41:27 -0500467
Jamie Madill3b7e2052014-03-17 09:47:43 -0400468 // HLSL code for initialization
Jamie Madilla53ab512014-03-17 09:47:44 -0400469 initHLSL += " " + decorateVariable(shaderAttribute.name) + " = ";
Jamie Madill8664b062014-02-14 16:41:29 -0500470
471 // Mismatched vertex attribute to vertex input may result in an undefined
472 // data reinterpretation (eg for pure integer->float, float->pure integer)
473 // TODO: issue warning with gl debug info extension, when supported
Jamie Madill3b7e2052014-03-17 09:47:43 -0400474 if (IsMatrixType(shaderAttribute.type) ||
Jamie Madilld3dfda22015-07-06 08:28:49 -0400475 (mRenderer->getVertexConversionType(vertexFormatType) & VERTEX_CONVERT_GPU) != 0)
Jamie Madill8664b062014-02-14 16:41:29 -0500476 {
Jamie Madilld3dfda22015-07-06 08:28:49 -0400477 initHLSL += generateAttributeConversionHLSL(vertexFormatType, shaderAttribute);
Jamie Madill8664b062014-02-14 16:41:29 -0500478 }
479 else
480 {
Jamie Madilla53ab512014-03-17 09:47:44 -0400481 initHLSL += "input." + decorateVariable(shaderAttribute.name);
Jamie Madill8664b062014-02-14 16:41:29 -0500482 }
483
Jamie Madill3b7e2052014-03-17 09:47:43 -0400484 initHLSL += ";\n";
Jamie Madill3b7e2052014-03-17 09:47:43 -0400485
Jamie Madillac0a2672014-04-11 13:33:56 -0400486 inputIndex += VariableRowCount(TransposeMatrixType(shaderAttribute.type));
487 }
Jamie Madillc5ede1a2014-02-14 16:41:27 -0500488 }
489
Geoff Lang04fb89a2014-06-09 15:05:36 -0400490 std::string replacementHLSL = "struct VS_INPUT\n"
491 "{\n" +
492 structHLSL +
493 "};\n"
494 "\n"
495 "void initAttributes(VS_INPUT input)\n"
496 "{\n" +
497 initHLSL +
498 "}\n";
499
500 std::string vertexHLSL(sourceShader);
501
502 size_t copyInsertionPos = vertexHLSL.find(VERTEX_ATTRIBUTE_STUB_STRING);
503 vertexHLSL.replace(copyInsertionPos, VERTEX_ATTRIBUTE_STUB_STRING.length(), replacementHLSL);
504
505 return vertexHLSL;
506}
507
Jamie Madillf6be8d72014-09-05 10:38:07 -0400508std::string DynamicHLSL::generatePixelShaderForOutputSignature(const std::string &sourceShader, const std::vector<PixelShaderOutputVariable> &outputVariables,
Geoff Lang04fb89a2014-06-09 15:05:36 -0400509 bool usesFragDepth, const std::vector<GLenum> &outputLayout) const
510{
511 const int shaderModel = mRenderer->getMajorShaderModel();
512 std::string targetSemantic = (shaderModel >= 4) ? "SV_TARGET" : "COLOR";
513 std::string depthSemantic = (shaderModel >= 4) ? "SV_Depth" : "DEPTH";
514
515 std::string declarationHLSL;
516 std::string copyHLSL;
Geoff Lang4ace4232014-06-18 19:12:48 -0400517
Jamie Madill3f2e61d2014-09-05 10:38:05 -0400518 for (size_t layoutIndex = 0; layoutIndex < outputLayout.size(); ++layoutIndex)
519 {
520 GLenum binding = outputLayout[layoutIndex];
521
522 if (binding != GL_NONE)
Geoff Lang04fb89a2014-06-09 15:05:36 -0400523 {
Jamie Madill3f2e61d2014-09-05 10:38:05 -0400524 unsigned int location = (binding - GL_COLOR_ATTACHMENT0);
525
Gregoire Payen de La Garanderiee1728542015-01-07 11:31:54 +0000526 const PixelShaderOutputVariable *outputVariable = FindOutputAtLocation(outputVariables, location);
Jamie Madill3f2e61d2014-09-05 10:38:05 -0400527
Gregoire Payen de La Garanderiee1728542015-01-07 11:31:54 +0000528 // OpenGL ES 3.0 spec $4.2.1
529 // If [...] not all user-defined output variables are written, the values of fragment colors
530 // corresponding to unwritten variables are similarly undefined.
531 if (outputVariable)
532 {
Cooper Partin4d61f7e2015-08-12 10:56:50 -0700533 declarationHLSL += " " + HLSLTypeString(outputVariable->type) + " " +
534 outputVariable->name + " : " + targetSemantic +
535 Str(static_cast<int>(layoutIndex)) + ";\n";
Geoff Lang04fb89a2014-06-09 15:05:36 -0400536
Gregoire Payen de La Garanderiee1728542015-01-07 11:31:54 +0000537 copyHLSL += " output." + outputVariable->name + " = " + outputVariable->source + ";\n";
538 }
Geoff Lang04fb89a2014-06-09 15:05:36 -0400539 }
540 }
541
542 if (usesFragDepth)
543 {
544 declarationHLSL += " float gl_Depth : " + depthSemantic + ";\n";
545 copyHLSL += " output.gl_Depth = gl_Depth; \n";
546 }
547
548 std::string replacementHLSL = "struct PS_OUTPUT\n"
549 "{\n" +
550 declarationHLSL +
551 "};\n"
552 "\n"
553 "PS_OUTPUT generateOutput()\n"
554 "{\n"
555 " PS_OUTPUT output;\n" +
556 copyHLSL +
557 " return output;\n"
558 "}\n";
559
560 std::string pixelHLSL(sourceShader);
561
562 size_t outputInsertionPos = pixelHLSL.find(PIXEL_OUTPUT_STUB_STRING);
563 pixelHLSL.replace(outputInsertionPos, PIXEL_OUTPUT_STUB_STRING.length(), replacementHLSL);
564
565 return pixelHLSL;
Jamie Madillc5ede1a2014-02-14 16:41:27 -0500566}
567
Jamie Madillfebb7ad2014-06-18 13:50:51 -0400568std::string DynamicHLSL::getVaryingSemantic(bool pointSize) const
569{
570 // SM3 reserves the TEXCOORD semantic for point sprite texcoords (gl_PointCoord)
571 // In D3D11 we manually compute gl_PointCoord in the GS.
572 int shaderModel = mRenderer->getMajorShaderModel();
573 return ((pointSize && shaderModel < 4) ? "COLOR" : "TEXCOORD");
574}
575
576struct DynamicHLSL::SemanticInfo
577{
578 struct BuiltinInfo
579 {
580 BuiltinInfo()
581 : enabled(false),
582 index(0),
583 systemValue(false)
584 {}
585
586 bool enabled;
587 std::string semantic;
588 unsigned int index;
589 bool systemValue;
590
591 std::string str() const
592 {
593 return (systemValue ? semantic : (semantic + Str(index)));
594 }
595
596 void enableSystem(const std::string &systemValueSemantic)
597 {
598 enabled = true;
599 semantic = systemValueSemantic;
600 systemValue = true;
601 }
602
603 void enable(const std::string &semanticVal, unsigned int indexVal)
604 {
605 enabled = true;
606 semantic = semanticVal;
607 index = indexVal;
608 }
609 };
610
611 BuiltinInfo dxPosition;
612 BuiltinInfo glPosition;
613 BuiltinInfo glFragCoord;
614 BuiltinInfo glPointCoord;
615 BuiltinInfo glPointSize;
616};
617
Austin Kinross8b695ee2015-03-12 13:12:20 -0700618DynamicHLSL::SemanticInfo DynamicHLSL::getSemanticInfo(int startRegisters, bool position, bool fragCoord,
619 bool pointCoord, bool pointSize, bool pixelShader) const
Jamie Madillfebb7ad2014-06-18 13:50:51 -0400620{
621 SemanticInfo info;
622 bool hlsl4 = (mRenderer->getMajorShaderModel() >= 4);
623 const std::string &varyingSemantic = getVaryingSemantic(pointSize);
624
625 int reservedRegisterIndex = startRegisters;
626
627 if (hlsl4)
628 {
629 info.dxPosition.enableSystem("SV_Position");
630 }
631 else if (pixelShader)
632 {
633 info.dxPosition.enableSystem("VPOS");
634 }
635 else
636 {
637 info.dxPosition.enableSystem("POSITION");
638 }
639
Austin Kinross8b695ee2015-03-12 13:12:20 -0700640 if (position)
641 {
642 info.glPosition.enable(varyingSemantic, reservedRegisterIndex++);
643 }
Jamie Madillfebb7ad2014-06-18 13:50:51 -0400644
645 if (fragCoord)
646 {
647 info.glFragCoord.enable(varyingSemantic, reservedRegisterIndex++);
648 }
649
650 if (pointCoord)
651 {
652 // SM3 reserves the TEXCOORD semantic for point sprite texcoords (gl_PointCoord)
653 // In D3D11 we manually compute gl_PointCoord in the GS.
654 if (hlsl4)
655 {
656 info.glPointCoord.enable(varyingSemantic, reservedRegisterIndex++);
657 }
658 else
659 {
660 info.glPointCoord.enable("TEXCOORD", 0);
661 }
662 }
663
664 // Special case: do not include PSIZE semantic in HLSL 3 pixel shaders
665 if (pointSize && (!pixelShader || hlsl4))
666 {
667 info.glPointSize.enableSystem("PSIZE");
668 }
669
670 return info;
671}
672
673std::string DynamicHLSL::generateVaryingLinkHLSL(const SemanticInfo &info, const std::string &varyingHLSL) const
674{
675 std::string linkHLSL = "{\n";
676
Austin Kinross8b695ee2015-03-12 13:12:20 -0700677 ASSERT(info.dxPosition.enabled);
Jamie Madillfebb7ad2014-06-18 13:50:51 -0400678 linkHLSL += " float4 dx_Position : " + info.dxPosition.str() + ";\n";
Austin Kinross8b695ee2015-03-12 13:12:20 -0700679
680 if (info.glPosition.enabled)
681 {
682 linkHLSL += " float4 gl_Position : " + info.glPosition.str() + ";\n";
683 }
Jamie Madillfebb7ad2014-06-18 13:50:51 -0400684
685 if (info.glFragCoord.enabled)
686 {
687 linkHLSL += " float4 gl_FragCoord : " + info.glFragCoord.str() + ";\n";
688 }
689
690 if (info.glPointCoord.enabled)
691 {
692 linkHLSL += " float2 gl_PointCoord : " + info.glPointCoord.str() + ";\n";
693 }
694
Jamie Madillfebb7ad2014-06-18 13:50:51 -0400695 if (info.glPointSize.enabled)
696 {
697 linkHLSL += " float gl_PointSize : " + info.glPointSize.str() + ";\n";
698 }
699
Austin Kinross8b695ee2015-03-12 13:12:20 -0700700 // Do this after glPointSize, to potentially combine gl_PointCoord and gl_PointSize into the same register.
701 linkHLSL += varyingHLSL;
702
Jamie Madillfebb7ad2014-06-18 13:50:51 -0400703 linkHLSL += "};\n";
704
705 return linkHLSL;
706}
707
708void DynamicHLSL::storeBuiltinLinkedVaryings(const SemanticInfo &info,
709 std::vector<LinkedVarying> *linkedVaryings) const
710{
Austin Kinross8b695ee2015-03-12 13:12:20 -0700711 if (info.glPosition.enabled)
712 {
713 linkedVaryings->push_back(LinkedVarying("gl_Position", GL_FLOAT_VEC4, 1, info.glPosition.semantic,
714 info.glPosition.index, 1));
715 }
Jamie Madillfebb7ad2014-06-18 13:50:51 -0400716
717 if (info.glFragCoord.enabled)
718 {
719 linkedVaryings->push_back(LinkedVarying("gl_FragCoord", GL_FLOAT_VEC4, 1, info.glFragCoord.semantic,
720 info.glFragCoord.index, 1));
721 }
722
723 if (info.glPointSize.enabled)
724 {
725 linkedVaryings->push_back(LinkedVarying("gl_PointSize", GL_FLOAT, 1, "PSIZE", 0, 1));
726 }
727}
728
Jamie Madillca03b352015-09-02 12:38:13 -0400729void DynamicHLSL::storeUserLinkedVaryings(const std::vector<PackedVarying> &packedVaryings,
730 bool shaderUsesPointSize,
Jamie Madillfebb7ad2014-06-18 13:50:51 -0400731 std::vector<LinkedVarying> *linkedVaryings) const
732{
Jamie Madillca03b352015-09-02 12:38:13 -0400733 const std::string &varyingSemantic = getVaryingSemantic(shaderUsesPointSize);
Jamie Madillfebb7ad2014-06-18 13:50:51 -0400734
Jamie Madillca03b352015-09-02 12:38:13 -0400735 for (const PackedVarying &packedVarying : packedVaryings)
Jamie Madillfebb7ad2014-06-18 13:50:51 -0400736 {
Jamie Madill4cff2472015-08-21 16:53:18 -0400737 if (packedVarying.registerAssigned())
Jamie Madillfebb7ad2014-06-18 13:50:51 -0400738 {
Jamie Madill4cff2472015-08-21 16:53:18 -0400739 const sh::Varying &varying = *packedVarying.varying;
740
Jamie Madill54ad4f82014-09-03 09:40:46 -0400741 ASSERT(!varying.isBuiltIn());
Jamie Madillfebb7ad2014-06-18 13:50:51 -0400742 GLenum transposedType = TransposeMatrixType(varying.type);
743 int variableRows = (varying.isStruct() ? 1 : VariableRowCount(transposedType));
744
Jamie Madill4cff2472015-08-21 16:53:18 -0400745 linkedVaryings->push_back(
746 LinkedVarying(varying.name, varying.type, varying.elementCount(), varyingSemantic,
747 packedVarying.registerIndex, variableRows * varying.elementCount()));
Jamie Madillfebb7ad2014-06-18 13:50:51 -0400748 }
749 }
750}
751
Jamie Madillada9ecc2015-08-17 12:53:37 -0400752bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data,
Jamie Madill80a6fc02015-08-21 16:53:16 -0400753 const gl::Program::Data &programData,
Jamie Madillada9ecc2015-08-17 12:53:37 -0400754 InfoLog &infoLog,
755 int registers,
Jamie Madillada9ecc2015-08-17 12:53:37 -0400756 std::string &pixelHLSL,
757 std::string &vertexHLSL,
Jamie Madillca03b352015-09-02 12:38:13 -0400758 const std::vector<PackedVarying> &packedVaryings,
Geoff Lang48dcae72014-02-05 16:28:24 -0500759 std::vector<LinkedVarying> *linkedVaryings,
Jamie Madillf6be8d72014-09-05 10:38:07 -0400760 std::vector<PixelShaderOutputVariable> *outPixelShaderKey,
Geoff Lang04fb89a2014-06-09 15:05:36 -0400761 bool *outUsesFragDepth) const
Jamie Madill5f562732014-02-14 16:41:24 -0500762{
763 if (pixelHLSL.empty() || vertexHLSL.empty())
764 {
765 return false;
766 }
767
Jamie Madill80a6fc02015-08-21 16:53:16 -0400768 const ShaderD3D *vertexShader = GetImplAs<ShaderD3D>(programData.getAttachedVertexShader());
769 const ShaderD3D *fragmentShader = GetImplAs<ShaderD3D>(programData.getAttachedFragmentShader());
770
Brandon Jones71620962014-08-20 14:04:59 -0700771 bool usesMRT = fragmentShader->mUsesMultipleRenderTargets;
Brandon Jones71620962014-08-20 14:04:59 -0700772 bool usesFragCoord = fragmentShader->mUsesFragCoord;
773 bool usesPointCoord = fragmentShader->mUsesPointCoord;
774 bool usesPointSize = vertexShader->mUsesPointSize;
Cooper Partine6664f02015-01-09 16:22:24 -0800775 bool useInstancedPointSpriteEmulation = usesPointSize && mRenderer->getWorkarounds().useInstancedPointSpriteEmulation;
Jamie Madillfebb7ad2014-06-18 13:50:51 -0400776
Jamie Madill14e95b32015-05-07 10:10:41 -0400777 // Validation done in the compiler
778 ASSERT(!fragmentShader->mUsesFragColor || !fragmentShader->mUsesFragData);
Jamie Madill5f562732014-02-14 16:41:24 -0500779
780 // Write the HLSL input/output declarations
781 const int shaderModel = mRenderer->getMajorShaderModel();
Jamie Madillfebb7ad2014-06-18 13:50:51 -0400782 const int registersNeeded = registers + (usesFragCoord ? 1 : 0) + (usesPointCoord ? 1 : 0);
Jamie Madill5f562732014-02-14 16:41:24 -0500783
784 // Two cases when writing to gl_FragColor and using ESSL 1.0:
785 // - with a 3.0 context, the output color is copied to channel 0
786 // - with a 2.0 context, the output color is broadcast to all channels
Jamie Madillde8892b2014-11-11 13:00:22 -0500787 const bool broadcast = (fragmentShader->mUsesFragColor && data.clientVersion < 3);
788 const unsigned int numRenderTargets = (broadcast || usesMRT ? data.caps->maxDrawBuffers : 1);
Jamie Madill5f562732014-02-14 16:41:24 -0500789
Austin Kinross8b695ee2015-03-12 13:12:20 -0700790 // gl_Position only needs to be outputted from the vertex shader if transform feedback is active.
791 // This isn't supported on D3D11 Feature Level 9_3, so we don't output gl_Position from the vertex shader in this case.
792 // This saves us 1 output vector.
793 bool outputPositionFromVS = !(shaderModel >= 4 && mRenderer->getShaderModelSuffix() != "");
794
Brandon Jones71620962014-08-20 14:04:59 -0700795 int shaderVersion = vertexShader->getShaderVersion();
Jamie Madill5f562732014-02-14 16:41:24 -0500796
Jamie Madillde8892b2014-11-11 13:00:22 -0500797 if (static_cast<GLuint>(registersNeeded) > data.caps->maxVaryingVectors)
Jamie Madill5f562732014-02-14 16:41:24 -0500798 {
Jamie Madillf6113162015-05-07 11:49:21 -0400799 infoLog << "No varying registers left to support gl_FragCoord/gl_PointCoord";
Jamie Madill5f562732014-02-14 16:41:24 -0500800 return false;
801 }
802
Jamie Madillca03b352015-09-02 12:38:13 -0400803 const std::string &varyingHLSL = generateVaryingHLSL(packedVaryings, usesPointSize);
Cooper Partine6664f02015-01-09 16:22:24 -0800804
805 // Instanced PointSprite emulation requires that gl_PointCoord is present in the vertex shader VS_OUTPUT
806 // structure to ensure compatibility with the generated PS_INPUT of the pixel shader.
807 // GeometryShader PointSprite emulation does not require this additional entry because the
808 // GS_OUTPUT of the Geometry shader contains the pointCoord value and already matches the PS_INPUT of the
809 // generated pixel shader.
Austin Kinross8b695ee2015-03-12 13:12:20 -0700810 // The Geometry Shader point sprite implementation needs gl_PointSize to be in VS_OUTPUT and GS_INPUT.
811 // Instanced point sprites doesn't need gl_PointSize in VS_OUTPUT.
812 const SemanticInfo &vertexSemantics = getSemanticInfo(registers, outputPositionFromVS,
813 usesFragCoord, (useInstancedPointSpriteEmulation && usesPointCoord),
814 (!useInstancedPointSpriteEmulation && usesPointSize), false);
Jamie Madill5f562732014-02-14 16:41:24 -0500815
Jamie Madillca03b352015-09-02 12:38:13 -0400816 storeUserLinkedVaryings(packedVaryings, usesPointSize, linkedVaryings);
Jamie Madillfebb7ad2014-06-18 13:50:51 -0400817 storeBuiltinLinkedVaryings(vertexSemantics, linkedVaryings);
Jamie Madill5f562732014-02-14 16:41:24 -0500818
Cooper Partine6664f02015-01-09 16:22:24 -0800819 // Instanced PointSprite emulation requires additional entries originally generated in the
820 // GeometryShader HLSL. These include pointsize clamp values.
821 if (useInstancedPointSpriteEmulation)
822 {
823 vertexHLSL += "static float minPointSize = " + Str((int)mRenderer->getRendererCaps().minAliasedPointSize) + ".0f;\n"
824 "static float maxPointSize = " + Str((int)mRenderer->getRendererCaps().maxAliasedPointSize) + ".0f;\n";
825 }
826
Jamie Madillc5ede1a2014-02-14 16:41:27 -0500827 // Add stub string to be replaced when shader is dynamically defined by its layout
Jamie Madillfebb7ad2014-06-18 13:50:51 -0400828 vertexHLSL += "\n" + VERTEX_ATTRIBUTE_STUB_STRING + "\n"
829 "struct VS_OUTPUT\n" + generateVaryingLinkHLSL(vertexSemantics, varyingHLSL) + "\n"
Jamie Madill5f562732014-02-14 16:41:24 -0500830 "VS_OUTPUT main(VS_INPUT input)\n"
Jamie Madillc5ede1a2014-02-14 16:41:27 -0500831 "{\n"
832 " initAttributes(input);\n";
Jamie Madill5f562732014-02-14 16:41:24 -0500833
Jamie Madill37997142015-01-28 10:06:34 -0500834 if (vertexShader->usesDeferredInit())
835 {
836 vertexHLSL += "\n"
837 " initializeDeferredGlobals();\n";
838 }
839
840 vertexHLSL += "\n"
841 " gl_main();\n"
842 "\n"
Austin Kinross8b695ee2015-03-12 13:12:20 -0700843 " VS_OUTPUT output;\n";
844
845 if (outputPositionFromVS)
846 {
847 vertexHLSL += " output.gl_Position = gl_Position;\n";
848 }
Jamie Madill37997142015-01-28 10:06:34 -0500849
Austin Kinross4fd18b12014-12-22 12:32:05 -0800850 // On D3D9 or D3D11 Feature Level 9, we need to emulate large viewports using dx_ViewAdjust.
851 if (shaderModel >= 4 && mRenderer->getShaderModelSuffix() == "")
Jamie Madill5f562732014-02-14 16:41:24 -0500852 {
Jamie Madill37997142015-01-28 10:06:34 -0500853 vertexHLSL += " output.dx_Position.x = gl_Position.x;\n"
Jamie Madill2bf8b372014-06-16 17:18:51 -0400854 " output.dx_Position.y = -gl_Position.y;\n"
855 " output.dx_Position.z = (gl_Position.z + gl_Position.w) * 0.5;\n"
856 " output.dx_Position.w = gl_Position.w;\n";
Jamie Madill5f562732014-02-14 16:41:24 -0500857 }
858 else
859 {
Jamie Madill37997142015-01-28 10:06:34 -0500860 vertexHLSL += " output.dx_Position.x = gl_Position.x * dx_ViewAdjust.z + dx_ViewAdjust.x * gl_Position.w;\n"
Jamie Madill2bf8b372014-06-16 17:18:51 -0400861 " output.dx_Position.y = -(gl_Position.y * dx_ViewAdjust.w + dx_ViewAdjust.y * gl_Position.w);\n"
862 " output.dx_Position.z = (gl_Position.z + gl_Position.w) * 0.5;\n"
863 " output.dx_Position.w = gl_Position.w;\n";
Jamie Madill5f562732014-02-14 16:41:24 -0500864 }
865
Austin Kinross8b695ee2015-03-12 13:12:20 -0700866 // We don't need to output gl_PointSize if we use are emulating point sprites via instancing.
867 if (usesPointSize && shaderModel >= 3 && !useInstancedPointSpriteEmulation)
Jamie Madill5f562732014-02-14 16:41:24 -0500868 {
869 vertexHLSL += " output.gl_PointSize = gl_PointSize;\n";
870 }
871
Jamie Madillfebb7ad2014-06-18 13:50:51 -0400872 if (usesFragCoord)
Jamie Madill5f562732014-02-14 16:41:24 -0500873 {
874 vertexHLSL += " output.gl_FragCoord = gl_Position;\n";
875 }
876
Jamie Madillca03b352015-09-02 12:38:13 -0400877 for (const PackedVarying &packedVarying : packedVaryings)
Jamie Madill5f562732014-02-14 16:41:24 -0500878 {
Jamie Madill4cff2472015-08-21 16:53:18 -0400879 if (!packedVarying.registerAssigned())
Jamie Madill5f562732014-02-14 16:41:24 -0500880 {
Jamie Madill4cff2472015-08-21 16:53:18 -0400881 continue;
882 }
883
884 const sh::Varying &varying = *packedVarying.varying;
885
886 for (unsigned int elementIndex = 0; elementIndex < varying.elementCount(); elementIndex++)
887 {
888 int variableRows =
889 (varying.isStruct() ? 1 : VariableRowCount(TransposeMatrixType(varying.type)));
890
891 for (int row = 0; row < variableRows; row++)
Jamie Madill5f562732014-02-14 16:41:24 -0500892 {
Jamie Madill4cff2472015-08-21 16:53:18 -0400893 int r = packedVarying.registerIndex +
894 packedVarying.columnIndex * data.caps->maxVaryingVectors +
895 elementIndex * variableRows + row;
896 vertexHLSL += " output.v" + Str(r);
Jamie Madill5f562732014-02-14 16:41:24 -0500897
Jamie Madill4cff2472015-08-21 16:53:18 -0400898 vertexHLSL += " = _" + varying.name;
899
900 if (varying.isArray())
Jamie Madill5f562732014-02-14 16:41:24 -0500901 {
Jamie Madill4cff2472015-08-21 16:53:18 -0400902 vertexHLSL += ArrayString(elementIndex);
Jamie Madill5f562732014-02-14 16:41:24 -0500903 }
Jamie Madill4cff2472015-08-21 16:53:18 -0400904
905 if (variableRows > 1)
906 {
907 vertexHLSL += ArrayString(row);
908 }
909
910 vertexHLSL += ";\n";
Jamie Madill5f562732014-02-14 16:41:24 -0500911 }
912 }
913 }
914
Cooper Partine6664f02015-01-09 16:22:24 -0800915 // Instanced PointSprite emulation requires additional entries to calculate
916 // the final output vertex positions of the quad that represents each sprite.
917 if (useInstancedPointSpriteEmulation)
918 {
919 vertexHLSL += "\n"
920 " gl_PointSize = clamp(gl_PointSize, minPointSize, maxPointSize);\n"
Austin Kinross8b695ee2015-03-12 13:12:20 -0700921 " output.dx_Position.xyz += float3(input.spriteVertexPos.x * gl_PointSize / (dx_ViewCoords.x*2), input.spriteVertexPos.y * gl_PointSize / (dx_ViewCoords.y*2), input.spriteVertexPos.z) * output.dx_Position.w;\n";
Cooper Partine6664f02015-01-09 16:22:24 -0800922
923 if (usesPointCoord)
924 {
925 vertexHLSL += "\n"
926 " output.gl_PointCoord = input.spriteTexCoord;\n";
927 }
928 }
929
Jamie Madill5f562732014-02-14 16:41:24 -0500930 vertexHLSL += "\n"
931 " return output;\n"
932 "}\n";
933
Austin Kinross8b695ee2015-03-12 13:12:20 -0700934 const SemanticInfo &pixelSemantics = getSemanticInfo(registers, outputPositionFromVS, usesFragCoord, usesPointCoord,
935 (!useInstancedPointSpriteEmulation && usesPointSize), true);
Jamie Madill5f562732014-02-14 16:41:24 -0500936
Jamie Madillfebb7ad2014-06-18 13:50:51 -0400937 pixelHLSL += "struct PS_INPUT\n" + generateVaryingLinkHLSL(pixelSemantics, varyingHLSL) + "\n";
Jamie Madill5f562732014-02-14 16:41:24 -0500938
939 if (shaderVersion < 300)
940 {
941 for (unsigned int renderTargetIndex = 0; renderTargetIndex < numRenderTargets; renderTargetIndex++)
942 {
Jamie Madillf6be8d72014-09-05 10:38:07 -0400943 PixelShaderOutputVariable outputKeyVariable;
Geoff Lang04fb89a2014-06-09 15:05:36 -0400944 outputKeyVariable.type = GL_FLOAT_VEC4;
945 outputKeyVariable.name = "gl_Color" + Str(renderTargetIndex);
946 outputKeyVariable.source = broadcast ? "gl_Color[0]" : "gl_Color[" + Str(renderTargetIndex) + "]";
947 outputKeyVariable.outputIndex = renderTargetIndex;
948
949 outPixelShaderKey->push_back(outputKeyVariable);
Jamie Madill5f562732014-02-14 16:41:24 -0500950 }
951
Brandon Jones71620962014-08-20 14:04:59 -0700952 *outUsesFragDepth = fragmentShader->mUsesFragDepth;
Jamie Madill5f562732014-02-14 16:41:24 -0500953 }
954 else
955 {
Jamie Madill80a6fc02015-08-21 16:53:16 -0400956 const auto &programOutputVars = programData.getOutputVariables();
Jamie Madill5f562732014-02-14 16:41:24 -0500957
Jamie Madilld15250e2014-09-03 09:40:44 -0400958 const std::vector<sh::Attribute> &shaderOutputVars = fragmentShader->getActiveOutputVariables();
Jamie Madill80a6fc02015-08-21 16:53:16 -0400959 for (auto outputPair : programOutputVars)
Jamie Madill5f562732014-02-14 16:41:24 -0500960 {
Jamie Madill80a6fc02015-08-21 16:53:16 -0400961 const VariableLocation &outputLocation = outputPair.second;
Jamie Madillf2575982014-06-25 16:04:54 -0400962 const sh::ShaderVariable &outputVariable = shaderOutputVars[outputLocation.index];
Geoff Lang04fb89a2014-06-09 15:05:36 -0400963 const std::string &variableName = "out_" + outputLocation.name;
Jamie Madill5f562732014-02-14 16:41:24 -0500964 const std::string &elementString = (outputLocation.element == GL_INVALID_INDEX ? "" : Str(outputLocation.element));
965
Jamie Madill54ad4f82014-09-03 09:40:46 -0400966 ASSERT(outputVariable.staticUse);
967
Jamie Madillf6be8d72014-09-05 10:38:07 -0400968 PixelShaderOutputVariable outputKeyVariable;
Geoff Lang04fb89a2014-06-09 15:05:36 -0400969 outputKeyVariable.type = outputVariable.type;
970 outputKeyVariable.name = variableName + elementString;
971 outputKeyVariable.source = variableName + ArrayString(outputLocation.element);
Jamie Madill80a6fc02015-08-21 16:53:16 -0400972 outputKeyVariable.outputIndex = outputPair.first;
Geoff Lang04fb89a2014-06-09 15:05:36 -0400973
974 outPixelShaderKey->push_back(outputKeyVariable);
Jamie Madill5f562732014-02-14 16:41:24 -0500975 }
Geoff Lang04fb89a2014-06-09 15:05:36 -0400976
977 *outUsesFragDepth = false;
Jamie Madill5f562732014-02-14 16:41:24 -0500978 }
979
Geoff Lang04fb89a2014-06-09 15:05:36 -0400980 pixelHLSL += PIXEL_OUTPUT_STUB_STRING + "\n";
Jamie Madill5f562732014-02-14 16:41:24 -0500981
Brandon Jones71620962014-08-20 14:04:59 -0700982 if (fragmentShader->mUsesFrontFacing)
Jamie Madill5f562732014-02-14 16:41:24 -0500983 {
984 if (shaderModel >= 4)
985 {
986 pixelHLSL += "PS_OUTPUT main(PS_INPUT input, bool isFrontFace : SV_IsFrontFace)\n"
987 "{\n";
988 }
989 else
990 {
991 pixelHLSL += "PS_OUTPUT main(PS_INPUT input, float vFace : VFACE)\n"
992 "{\n";
993 }
994 }
995 else
996 {
997 pixelHLSL += "PS_OUTPUT main(PS_INPUT input)\n"
998 "{\n";
999 }
1000
Jamie Madillfebb7ad2014-06-18 13:50:51 -04001001 if (usesFragCoord)
Jamie Madill5f562732014-02-14 16:41:24 -05001002 {
1003 pixelHLSL += " float rhw = 1.0 / input.gl_FragCoord.w;\n";
1004
Austin Kinross588434c2014-12-10 10:41:45 -08001005 // Certain Shader Models (4_0+ and 3_0) allow reading from dx_Position in the pixel shader.
1006 // Other Shader Models (4_0_level_9_3 and 2_x) don't support this, so we emulate it using dx_ViewCoords.
1007 if (shaderModel >= 4 && mRenderer->getShaderModelSuffix() == "")
Jamie Madill5f562732014-02-14 16:41:24 -05001008 {
Jamie Madillfebb7ad2014-06-18 13:50:51 -04001009 pixelHLSL += " gl_FragCoord.x = input.dx_Position.x;\n"
1010 " gl_FragCoord.y = input.dx_Position.y;\n";
Jamie Madill5f562732014-02-14 16:41:24 -05001011 }
Austin Kinross588434c2014-12-10 10:41:45 -08001012 else if (shaderModel == 3)
Jamie Madill5f562732014-02-14 16:41:24 -05001013 {
Jamie Madillfebb7ad2014-06-18 13:50:51 -04001014 pixelHLSL += " gl_FragCoord.x = input.dx_Position.x + 0.5;\n"
1015 " gl_FragCoord.y = input.dx_Position.y + 0.5;\n";
Jamie Madill5f562732014-02-14 16:41:24 -05001016 }
1017 else
1018 {
1019 // dx_ViewCoords contains the viewport width/2, height/2, center.x and center.y. See Renderer::setViewport()
1020 pixelHLSL += " gl_FragCoord.x = (input.gl_FragCoord.x * rhw) * dx_ViewCoords.x + dx_ViewCoords.z;\n"
1021 " gl_FragCoord.y = (input.gl_FragCoord.y * rhw) * dx_ViewCoords.y + dx_ViewCoords.w;\n";
1022 }
1023
1024 pixelHLSL += " gl_FragCoord.z = (input.gl_FragCoord.z * rhw) * dx_DepthFront.x + dx_DepthFront.y;\n"
1025 " gl_FragCoord.w = rhw;\n";
1026 }
1027
Jamie Madillfebb7ad2014-06-18 13:50:51 -04001028 if (usesPointCoord && shaderModel >= 3)
Jamie Madill5f562732014-02-14 16:41:24 -05001029 {
1030 pixelHLSL += " gl_PointCoord.x = input.gl_PointCoord.x;\n";
1031 pixelHLSL += " gl_PointCoord.y = 1.0 - input.gl_PointCoord.y;\n";
1032 }
1033
Brandon Jones71620962014-08-20 14:04:59 -07001034 if (fragmentShader->mUsesFrontFacing)
Jamie Madill5f562732014-02-14 16:41:24 -05001035 {
1036 if (shaderModel <= 3)
1037 {
1038 pixelHLSL += " gl_FrontFacing = (vFace * dx_DepthFront.z >= 0.0);\n";
1039 }
1040 else
1041 {
1042 pixelHLSL += " gl_FrontFacing = isFrontFace;\n";
1043 }
1044 }
1045
Jamie Madillca03b352015-09-02 12:38:13 -04001046 for (const PackedVarying &packedVarying : packedVaryings)
Jamie Madill5f562732014-02-14 16:41:24 -05001047 {
Jamie Madill4cff2472015-08-21 16:53:18 -04001048 const sh::Varying &varying = *packedVarying.varying;
1049
1050 if (!packedVarying.registerAssigned())
Jamie Madill5f562732014-02-14 16:41:24 -05001051 {
Jamie Madill4cff2472015-08-21 16:53:18 -04001052 ASSERT(varying.isBuiltIn() || !varying.staticUse);
1053 continue;
1054 }
1055
Jamie Madillca03b352015-09-02 12:38:13 -04001056 // Don't reference VS-only transform feedback varyings in the PS.
1057 if (packedVarying.vertexOnly)
1058 continue;
1059
Jamie Madill4cff2472015-08-21 16:53:18 -04001060 ASSERT(!varying.isBuiltIn());
1061 for (unsigned int elementIndex = 0; elementIndex < varying.elementCount(); elementIndex++)
1062 {
1063 GLenum transposedType = TransposeMatrixType(varying.type);
1064 int variableRows = (varying.isStruct() ? 1 : VariableRowCount(transposedType));
1065 for (int row = 0; row < variableRows; row++)
Jamie Madill5f562732014-02-14 16:41:24 -05001066 {
Jamie Madill4cff2472015-08-21 16:53:18 -04001067 std::string n = Str(packedVarying.registerIndex +
1068 packedVarying.columnIndex * data.caps->maxVaryingVectors +
1069 elementIndex * variableRows + row);
1070 pixelHLSL += " _" + varying.name;
1071
1072 if (varying.isArray())
Jamie Madill5f562732014-02-14 16:41:24 -05001073 {
Jamie Madill4cff2472015-08-21 16:53:18 -04001074 pixelHLSL += ArrayString(elementIndex);
1075 }
Jamie Madill5f562732014-02-14 16:41:24 -05001076
Jamie Madill4cff2472015-08-21 16:53:18 -04001077 if (variableRows > 1)
1078 {
1079 pixelHLSL += ArrayString(row);
1080 }
Jamie Madill5f562732014-02-14 16:41:24 -05001081
Jamie Madill4cff2472015-08-21 16:53:18 -04001082 if (varying.isStruct())
1083 {
1084 pixelHLSL += " = input.v" + n + ";\n";
1085 break;
1086 }
1087 else
1088 {
1089 switch (VariableColumnCount(transposedType))
Jamie Madill5f562732014-02-14 16:41:24 -05001090 {
Jamie Madill4cff2472015-08-21 16:53:18 -04001091 case 1:
1092 pixelHLSL += " = input.v" + n + ".x;\n";
1093 break;
1094 case 2:
1095 pixelHLSL += " = input.v" + n + ".xy;\n";
1096 break;
1097 case 3:
1098 pixelHLSL += " = input.v" + n + ".xyz;\n";
1099 break;
1100 case 4:
1101 pixelHLSL += " = input.v" + n + ";\n";
1102 break;
1103 default:
1104 UNREACHABLE();
Jamie Madill5f562732014-02-14 16:41:24 -05001105 }
1106 }
1107 }
1108 }
Jamie Madill5f562732014-02-14 16:41:24 -05001109 }
1110
Jamie Madill37997142015-01-28 10:06:34 -05001111 if (fragmentShader->usesDeferredInit())
1112 {
1113 pixelHLSL += "\n"
1114 " initializeDeferredGlobals();\n";
1115 }
1116
Jamie Madill5f562732014-02-14 16:41:24 -05001117 pixelHLSL += "\n"
1118 " gl_main();\n"
1119 "\n"
Geoff Lang04fb89a2014-06-09 15:05:36 -04001120 " return generateOutput();\n"
Jamie Madill5f562732014-02-14 16:41:24 -05001121 "}\n";
1122
1123 return true;
1124}
1125
Jamie Madillca03b352015-09-02 12:38:13 -04001126std::string DynamicHLSL::generateGeometryShaderHLSL(
1127 int registers,
1128 const ShaderD3D *fragmentShader,
1129 const std::vector<PackedVarying> &packedVaryings) const
Jamie Madill5f562732014-02-14 16:41:24 -05001130{
1131 // for now we only handle point sprite emulation
Jamie Madillca03b352015-09-02 12:38:13 -04001132 ASSERT(mRenderer->getMajorShaderModel() >= 4);
1133 return generatePointSpriteHLSL(registers, fragmentShader, packedVaryings);
Jamie Madill5f562732014-02-14 16:41:24 -05001134}
1135
Jamie Madillca03b352015-09-02 12:38:13 -04001136std::string DynamicHLSL::generatePointSpriteHLSL(
1137 int registers,
1138 const ShaderD3D *fragmentShader,
1139 const std::vector<PackedVarying> &packedVaryings) const
Jamie Madill5f562732014-02-14 16:41:24 -05001140{
1141 ASSERT(registers >= 0);
Jamie Madill5f562732014-02-14 16:41:24 -05001142 ASSERT(mRenderer->getMajorShaderModel() >= 4);
1143
1144 std::string geomHLSL;
1145
Austin Kinross8b695ee2015-03-12 13:12:20 -07001146 const SemanticInfo &inSemantics = getSemanticInfo(registers, true, fragmentShader->mUsesFragCoord,
Jamie Madillfebb7ad2014-06-18 13:50:51 -04001147 false, true, false);
Austin Kinross8b695ee2015-03-12 13:12:20 -07001148 const SemanticInfo &outSemantics = getSemanticInfo(registers, true, fragmentShader->mUsesFragCoord,
Brandon Jones71620962014-08-20 14:04:59 -07001149 fragmentShader->mUsesPointCoord, true, false);
Jamie Madill5f562732014-02-14 16:41:24 -05001150
Jamie Madillca03b352015-09-02 12:38:13 -04001151 // If we're generating the geometry shader, we assume the vertex shader uses point size.
1152 std::string varyingHLSL = generateVaryingHLSL(packedVaryings, true);
Jamie Madillfebb7ad2014-06-18 13:50:51 -04001153 std::string inLinkHLSL = generateVaryingLinkHLSL(inSemantics, varyingHLSL);
1154 std::string outLinkHLSL = generateVaryingLinkHLSL(outSemantics, varyingHLSL);
Jamie Madill5f562732014-02-14 16:41:24 -05001155
Geoff Langc0b9ef42014-07-02 10:02:37 -04001156 // TODO(geofflang): use context's caps
Jamie Madill5f562732014-02-14 16:41:24 -05001157 geomHLSL += "uniform float4 dx_ViewCoords : register(c1);\n"
1158 "\n"
Jamie Madillfebb7ad2014-06-18 13:50:51 -04001159 "struct GS_INPUT\n" + inLinkHLSL + "\n" +
1160 "struct GS_OUTPUT\n" + outLinkHLSL + "\n" +
Jamie Madill5f562732014-02-14 16:41:24 -05001161 "\n"
Jamie Madill37997142015-01-28 10:06:34 -05001162 "static float2 pointSpriteCorners[] = \n"
1163 "{\n"
1164 " float2( 0.5f, -0.5f),\n"
1165 " float2( 0.5f, 0.5f),\n"
1166 " float2(-0.5f, -0.5f),\n"
1167 " float2(-0.5f, 0.5f)\n"
1168 "};\n"
1169 "\n"
1170 "static float2 pointSpriteTexcoords[] = \n"
1171 "{\n"
1172 " float2(1.0f, 1.0f),\n"
1173 " float2(1.0f, 0.0f),\n"
1174 " float2(0.0f, 1.0f),\n"
1175 " float2(0.0f, 0.0f)\n"
1176 "};\n"
1177 "\n"
Minmin Gong794e0002015-04-07 18:31:54 -07001178 "static float minPointSize = " + Str(static_cast<int>(mRenderer->getRendererCaps().minAliasedPointSize)) + ".0f;\n"
1179 "static float maxPointSize = " + Str(static_cast<int>(mRenderer->getRendererCaps().maxAliasedPointSize)) + ".0f;\n"
Jamie Madill37997142015-01-28 10:06:34 -05001180 "\n"
1181 "[maxvertexcount(4)]\n"
1182 "void main(point GS_INPUT input[1], inout TriangleStream<GS_OUTPUT> outStream)\n"
1183 "{\n"
1184 " GS_OUTPUT output = (GS_OUTPUT)0;\n"
1185 " output.gl_Position = input[0].gl_Position;\n"
1186 " output.gl_PointSize = input[0].gl_PointSize;\n";
Jamie Madill5f562732014-02-14 16:41:24 -05001187
1188 for (int r = 0; r < registers; r++)
1189 {
1190 geomHLSL += " output.v" + Str(r) + " = input[0].v" + Str(r) + ";\n";
1191 }
1192
Brandon Jones71620962014-08-20 14:04:59 -07001193 if (fragmentShader->mUsesFragCoord)
Jamie Madill5f562732014-02-14 16:41:24 -05001194 {
1195 geomHLSL += " output.gl_FragCoord = input[0].gl_FragCoord;\n";
1196 }
1197
1198 geomHLSL += " \n"
1199 " float gl_PointSize = clamp(input[0].gl_PointSize, minPointSize, maxPointSize);\n"
Jamie Madillfebb7ad2014-06-18 13:50:51 -04001200 " float4 dx_Position = input[0].dx_Position;\n"
1201 " float2 viewportScale = float2(1.0f / dx_ViewCoords.x, 1.0f / dx_ViewCoords.y) * dx_Position.w;\n";
Jamie Madill5f562732014-02-14 16:41:24 -05001202
1203 for (int corner = 0; corner < 4; corner++)
1204 {
1205 geomHLSL += " \n"
Jamie Madillfebb7ad2014-06-18 13:50:51 -04001206 " output.dx_Position = dx_Position + float4(pointSpriteCorners[" + Str(corner) + "] * viewportScale * gl_PointSize, 0.0f, 0.0f);\n";
Jamie Madill5f562732014-02-14 16:41:24 -05001207
Brandon Jones71620962014-08-20 14:04:59 -07001208 if (fragmentShader->mUsesPointCoord)
Jamie Madill5f562732014-02-14 16:41:24 -05001209 {
1210 geomHLSL += " output.gl_PointCoord = pointSpriteTexcoords[" + Str(corner) + "];\n";
1211 }
1212
1213 geomHLSL += " outStream.Append(output);\n";
1214 }
1215
1216 geomHLSL += " \n"
1217 " outStream.RestartStrip();\n"
1218 "}\n";
1219
1220 return geomHLSL;
1221}
1222
1223// This method needs to match OutputHLSL::decorate
Jamie Madilla53ab512014-03-17 09:47:44 -04001224std::string DynamicHLSL::decorateVariable(const std::string &name)
Jamie Madill5f562732014-02-14 16:41:24 -05001225{
Jamie Madilld5512cd2014-07-10 17:50:08 -04001226 if (name.compare(0, 3, "gl_") != 0)
Jamie Madill5f562732014-02-14 16:41:24 -05001227 {
1228 return "_" + name;
1229 }
1230
1231 return name;
1232}
1233
Jamie Madilld3dfda22015-07-06 08:28:49 -04001234std::string DynamicHLSL::generateAttributeConversionHLSL(gl::VertexFormatType vertexFormatType,
1235 const sh::ShaderVariable &shaderAttrib) const
Jamie Madillc5ede1a2014-02-14 16:41:27 -05001236{
Jamie Madilld3dfda22015-07-06 08:28:49 -04001237 const gl::VertexFormat &vertexFormat = gl::GetVertexFormatFromType(vertexFormatType);
Jamie Madilla53ab512014-03-17 09:47:44 -04001238 std::string attribString = "input." + decorateVariable(shaderAttrib.name);
Jamie Madill8664b062014-02-14 16:41:29 -05001239
Jamie Madillc5ede1a2014-02-14 16:41:27 -05001240 // Matrix
1241 if (IsMatrixType(shaderAttrib.type))
1242 {
Jamie Madill8664b062014-02-14 16:41:29 -05001243 return "transpose(" + attribString + ")";
Jamie Madillc5ede1a2014-02-14 16:41:27 -05001244 }
1245
Jamie Madillf2575982014-06-25 16:04:54 -04001246 GLenum shaderComponentType = VariableComponentType(shaderAttrib.type);
1247 int shaderComponentCount = VariableComponentCount(shaderAttrib.type);
Jamie Madill8664b062014-02-14 16:41:29 -05001248
Jamie Madill8664b062014-02-14 16:41:29 -05001249 // Perform integer to float conversion (if necessary)
Jamie Madilld3dfda22015-07-06 08:28:49 -04001250 bool requiresTypeConversion = (shaderComponentType == GL_FLOAT && vertexFormat.type != GL_FLOAT);
Jamie Madill8664b062014-02-14 16:41:29 -05001251
Jamie Madill7a29e4a2014-05-02 10:41:48 -04001252 if (requiresTypeConversion)
Jamie Madill8664b062014-02-14 16:41:29 -05001253 {
Jamie Madill7a29e4a2014-05-02 10:41:48 -04001254 // TODO: normalization for 32-bit integer formats
Jamie Madilld3dfda22015-07-06 08:28:49 -04001255 ASSERT(!vertexFormat.normalized && !vertexFormat.pureInteger);
Jamie Madill7a29e4a2014-05-02 10:41:48 -04001256 return "float" + Str(shaderComponentCount) + "(" + attribString + ")";
Jamie Madill8664b062014-02-14 16:41:29 -05001257 }
Jamie Madillc5ede1a2014-02-14 16:41:27 -05001258
1259 // No conversion necessary
Jamie Madill8664b062014-02-14 16:41:29 -05001260 return attribString;
Jamie Madillc5ede1a2014-02-14 16:41:27 -05001261}
1262
Jamie Madill5f562732014-02-14 16:41:24 -05001263}