blob: 6e386f937c2357a8241ed4cf06c464349b38ef21 [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 Madill91445bc2015-09-23 16:47:53 -0400768 const gl::Shader *vertexShaderGL = programData.getAttachedVertexShader();
769 const ShaderD3D *vertexShader = GetImplAs<ShaderD3D>(vertexShaderGL);
770 const gl::Shader *fragmentShaderGL = programData.getAttachedFragmentShader();
771 const ShaderD3D *fragmentShader = GetImplAs<ShaderD3D>(fragmentShaderGL);
Jamie Madill80a6fc02015-08-21 16:53:16 -0400772
Brandon Jones71620962014-08-20 14:04:59 -0700773 bool usesMRT = fragmentShader->mUsesMultipleRenderTargets;
Brandon Jones71620962014-08-20 14:04:59 -0700774 bool usesFragCoord = fragmentShader->mUsesFragCoord;
775 bool usesPointCoord = fragmentShader->mUsesPointCoord;
776 bool usesPointSize = vertexShader->mUsesPointSize;
Cooper Partine6664f02015-01-09 16:22:24 -0800777 bool useInstancedPointSpriteEmulation = usesPointSize && mRenderer->getWorkarounds().useInstancedPointSpriteEmulation;
Jamie Madillfebb7ad2014-06-18 13:50:51 -0400778
Jamie Madill14e95b32015-05-07 10:10:41 -0400779 // Validation done in the compiler
780 ASSERT(!fragmentShader->mUsesFragColor || !fragmentShader->mUsesFragData);
Jamie Madill5f562732014-02-14 16:41:24 -0500781
782 // Write the HLSL input/output declarations
783 const int shaderModel = mRenderer->getMajorShaderModel();
Jamie Madillfebb7ad2014-06-18 13:50:51 -0400784 const int registersNeeded = registers + (usesFragCoord ? 1 : 0) + (usesPointCoord ? 1 : 0);
Jamie Madill5f562732014-02-14 16:41:24 -0500785
786 // Two cases when writing to gl_FragColor and using ESSL 1.0:
787 // - with a 3.0 context, the output color is copied to channel 0
788 // - with a 2.0 context, the output color is broadcast to all channels
Jamie Madillde8892b2014-11-11 13:00:22 -0500789 const bool broadcast = (fragmentShader->mUsesFragColor && data.clientVersion < 3);
790 const unsigned int numRenderTargets = (broadcast || usesMRT ? data.caps->maxDrawBuffers : 1);
Jamie Madill5f562732014-02-14 16:41:24 -0500791
Austin Kinross8b695ee2015-03-12 13:12:20 -0700792 // gl_Position only needs to be outputted from the vertex shader if transform feedback is active.
793 // This isn't supported on D3D11 Feature Level 9_3, so we don't output gl_Position from the vertex shader in this case.
794 // This saves us 1 output vector.
795 bool outputPositionFromVS = !(shaderModel >= 4 && mRenderer->getShaderModelSuffix() != "");
796
Jamie Madill91445bc2015-09-23 16:47:53 -0400797 int shaderVersion = vertexShaderGL->getShaderVersion();
Jamie Madill5f562732014-02-14 16:41:24 -0500798
Jamie Madillde8892b2014-11-11 13:00:22 -0500799 if (static_cast<GLuint>(registersNeeded) > data.caps->maxVaryingVectors)
Jamie Madill5f562732014-02-14 16:41:24 -0500800 {
Jamie Madillf6113162015-05-07 11:49:21 -0400801 infoLog << "No varying registers left to support gl_FragCoord/gl_PointCoord";
Jamie Madill5f562732014-02-14 16:41:24 -0500802 return false;
803 }
804
Jamie Madillca03b352015-09-02 12:38:13 -0400805 const std::string &varyingHLSL = generateVaryingHLSL(packedVaryings, usesPointSize);
Cooper Partine6664f02015-01-09 16:22:24 -0800806
807 // Instanced PointSprite emulation requires that gl_PointCoord is present in the vertex shader VS_OUTPUT
808 // structure to ensure compatibility with the generated PS_INPUT of the pixel shader.
809 // GeometryShader PointSprite emulation does not require this additional entry because the
810 // GS_OUTPUT of the Geometry shader contains the pointCoord value and already matches the PS_INPUT of the
811 // generated pixel shader.
Austin Kinross8b695ee2015-03-12 13:12:20 -0700812 // The Geometry Shader point sprite implementation needs gl_PointSize to be in VS_OUTPUT and GS_INPUT.
813 // Instanced point sprites doesn't need gl_PointSize in VS_OUTPUT.
814 const SemanticInfo &vertexSemantics = getSemanticInfo(registers, outputPositionFromVS,
815 usesFragCoord, (useInstancedPointSpriteEmulation && usesPointCoord),
816 (!useInstancedPointSpriteEmulation && usesPointSize), false);
Jamie Madill5f562732014-02-14 16:41:24 -0500817
Jamie Madillca03b352015-09-02 12:38:13 -0400818 storeUserLinkedVaryings(packedVaryings, usesPointSize, linkedVaryings);
Jamie Madillfebb7ad2014-06-18 13:50:51 -0400819 storeBuiltinLinkedVaryings(vertexSemantics, linkedVaryings);
Jamie Madill5f562732014-02-14 16:41:24 -0500820
Cooper Partine6664f02015-01-09 16:22:24 -0800821 // Instanced PointSprite emulation requires additional entries originally generated in the
822 // GeometryShader HLSL. These include pointsize clamp values.
823 if (useInstancedPointSpriteEmulation)
824 {
825 vertexHLSL += "static float minPointSize = " + Str((int)mRenderer->getRendererCaps().minAliasedPointSize) + ".0f;\n"
826 "static float maxPointSize = " + Str((int)mRenderer->getRendererCaps().maxAliasedPointSize) + ".0f;\n";
827 }
828
Jamie Madillc5ede1a2014-02-14 16:41:27 -0500829 // Add stub string to be replaced when shader is dynamically defined by its layout
Jamie Madillfebb7ad2014-06-18 13:50:51 -0400830 vertexHLSL += "\n" + VERTEX_ATTRIBUTE_STUB_STRING + "\n"
831 "struct VS_OUTPUT\n" + generateVaryingLinkHLSL(vertexSemantics, varyingHLSL) + "\n"
Jamie Madill5f562732014-02-14 16:41:24 -0500832 "VS_OUTPUT main(VS_INPUT input)\n"
Jamie Madillc5ede1a2014-02-14 16:41:27 -0500833 "{\n"
834 " initAttributes(input);\n";
Jamie Madill5f562732014-02-14 16:41:24 -0500835
Jamie Madill37997142015-01-28 10:06:34 -0500836 if (vertexShader->usesDeferredInit())
837 {
838 vertexHLSL += "\n"
839 " initializeDeferredGlobals();\n";
840 }
841
842 vertexHLSL += "\n"
843 " gl_main();\n"
844 "\n"
Austin Kinross8b695ee2015-03-12 13:12:20 -0700845 " VS_OUTPUT output;\n";
846
847 if (outputPositionFromVS)
848 {
849 vertexHLSL += " output.gl_Position = gl_Position;\n";
850 }
Jamie Madill37997142015-01-28 10:06:34 -0500851
Austin Kinross4fd18b12014-12-22 12:32:05 -0800852 // On D3D9 or D3D11 Feature Level 9, we need to emulate large viewports using dx_ViewAdjust.
853 if (shaderModel >= 4 && mRenderer->getShaderModelSuffix() == "")
Jamie Madill5f562732014-02-14 16:41:24 -0500854 {
Jamie Madill37997142015-01-28 10:06:34 -0500855 vertexHLSL += " output.dx_Position.x = gl_Position.x;\n"
Jamie Madill2bf8b372014-06-16 17:18:51 -0400856 " output.dx_Position.y = -gl_Position.y;\n"
857 " output.dx_Position.z = (gl_Position.z + gl_Position.w) * 0.5;\n"
858 " output.dx_Position.w = gl_Position.w;\n";
Jamie Madill5f562732014-02-14 16:41:24 -0500859 }
860 else
861 {
Jamie Madill37997142015-01-28 10:06:34 -0500862 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 -0400863 " output.dx_Position.y = -(gl_Position.y * dx_ViewAdjust.w + dx_ViewAdjust.y * gl_Position.w);\n"
864 " output.dx_Position.z = (gl_Position.z + gl_Position.w) * 0.5;\n"
865 " output.dx_Position.w = gl_Position.w;\n";
Jamie Madill5f562732014-02-14 16:41:24 -0500866 }
867
Austin Kinross8b695ee2015-03-12 13:12:20 -0700868 // We don't need to output gl_PointSize if we use are emulating point sprites via instancing.
869 if (usesPointSize && shaderModel >= 3 && !useInstancedPointSpriteEmulation)
Jamie Madill5f562732014-02-14 16:41:24 -0500870 {
871 vertexHLSL += " output.gl_PointSize = gl_PointSize;\n";
872 }
873
Jamie Madillfebb7ad2014-06-18 13:50:51 -0400874 if (usesFragCoord)
Jamie Madill5f562732014-02-14 16:41:24 -0500875 {
876 vertexHLSL += " output.gl_FragCoord = gl_Position;\n";
877 }
878
Jamie Madillca03b352015-09-02 12:38:13 -0400879 for (const PackedVarying &packedVarying : packedVaryings)
Jamie Madill5f562732014-02-14 16:41:24 -0500880 {
Jamie Madill4cff2472015-08-21 16:53:18 -0400881 if (!packedVarying.registerAssigned())
Jamie Madill5f562732014-02-14 16:41:24 -0500882 {
Jamie Madill4cff2472015-08-21 16:53:18 -0400883 continue;
884 }
885
886 const sh::Varying &varying = *packedVarying.varying;
887
888 for (unsigned int elementIndex = 0; elementIndex < varying.elementCount(); elementIndex++)
889 {
890 int variableRows =
891 (varying.isStruct() ? 1 : VariableRowCount(TransposeMatrixType(varying.type)));
892
893 for (int row = 0; row < variableRows; row++)
Jamie Madill5f562732014-02-14 16:41:24 -0500894 {
Jamie Madill4cff2472015-08-21 16:53:18 -0400895 int r = packedVarying.registerIndex +
896 packedVarying.columnIndex * data.caps->maxVaryingVectors +
897 elementIndex * variableRows + row;
898 vertexHLSL += " output.v" + Str(r);
Jamie Madill5f562732014-02-14 16:41:24 -0500899
Jamie Madill4cff2472015-08-21 16:53:18 -0400900 vertexHLSL += " = _" + varying.name;
901
902 if (varying.isArray())
Jamie Madill5f562732014-02-14 16:41:24 -0500903 {
Jamie Madill4cff2472015-08-21 16:53:18 -0400904 vertexHLSL += ArrayString(elementIndex);
Jamie Madill5f562732014-02-14 16:41:24 -0500905 }
Jamie Madill4cff2472015-08-21 16:53:18 -0400906
907 if (variableRows > 1)
908 {
909 vertexHLSL += ArrayString(row);
910 }
911
912 vertexHLSL += ";\n";
Jamie Madill5f562732014-02-14 16:41:24 -0500913 }
914 }
915 }
916
Cooper Partine6664f02015-01-09 16:22:24 -0800917 // Instanced PointSprite emulation requires additional entries to calculate
918 // the final output vertex positions of the quad that represents each sprite.
919 if (useInstancedPointSpriteEmulation)
920 {
921 vertexHLSL += "\n"
922 " gl_PointSize = clamp(gl_PointSize, minPointSize, maxPointSize);\n"
Austin Kinross8b695ee2015-03-12 13:12:20 -0700923 " 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 -0800924
925 if (usesPointCoord)
926 {
927 vertexHLSL += "\n"
928 " output.gl_PointCoord = input.spriteTexCoord;\n";
929 }
930 }
931
Jamie Madill5f562732014-02-14 16:41:24 -0500932 vertexHLSL += "\n"
933 " return output;\n"
934 "}\n";
935
Austin Kinross8b695ee2015-03-12 13:12:20 -0700936 const SemanticInfo &pixelSemantics = getSemanticInfo(registers, outputPositionFromVS, usesFragCoord, usesPointCoord,
937 (!useInstancedPointSpriteEmulation && usesPointSize), true);
Jamie Madill5f562732014-02-14 16:41:24 -0500938
Jamie Madillfebb7ad2014-06-18 13:50:51 -0400939 pixelHLSL += "struct PS_INPUT\n" + generateVaryingLinkHLSL(pixelSemantics, varyingHLSL) + "\n";
Jamie Madill5f562732014-02-14 16:41:24 -0500940
941 if (shaderVersion < 300)
942 {
943 for (unsigned int renderTargetIndex = 0; renderTargetIndex < numRenderTargets; renderTargetIndex++)
944 {
Jamie Madillf6be8d72014-09-05 10:38:07 -0400945 PixelShaderOutputVariable outputKeyVariable;
Geoff Lang04fb89a2014-06-09 15:05:36 -0400946 outputKeyVariable.type = GL_FLOAT_VEC4;
947 outputKeyVariable.name = "gl_Color" + Str(renderTargetIndex);
948 outputKeyVariable.source = broadcast ? "gl_Color[0]" : "gl_Color[" + Str(renderTargetIndex) + "]";
949 outputKeyVariable.outputIndex = renderTargetIndex;
950
951 outPixelShaderKey->push_back(outputKeyVariable);
Jamie Madill5f562732014-02-14 16:41:24 -0500952 }
953
Brandon Jones71620962014-08-20 14:04:59 -0700954 *outUsesFragDepth = fragmentShader->mUsesFragDepth;
Jamie Madill5f562732014-02-14 16:41:24 -0500955 }
956 else
957 {
Jamie Madill91445bc2015-09-23 16:47:53 -0400958 const auto &shaderOutputVars = fragmentShaderGL->getActiveOutputVariables();
Jamie Madill5f562732014-02-14 16:41:24 -0500959
Jamie Madilla0a9e122015-09-02 15:54:30 -0400960 for (auto outputPair : programData.getOutputVariables())
Jamie Madill5f562732014-02-14 16:41:24 -0500961 {
Jamie Madill80a6fc02015-08-21 16:53:16 -0400962 const VariableLocation &outputLocation = outputPair.second;
Jamie Madillf2575982014-06-25 16:04:54 -0400963 const sh::ShaderVariable &outputVariable = shaderOutputVars[outputLocation.index];
Geoff Lang04fb89a2014-06-09 15:05:36 -0400964 const std::string &variableName = "out_" + outputLocation.name;
Jamie Madill5f562732014-02-14 16:41:24 -0500965 const std::string &elementString = (outputLocation.element == GL_INVALID_INDEX ? "" : Str(outputLocation.element));
966
Jamie Madill54ad4f82014-09-03 09:40:46 -0400967 ASSERT(outputVariable.staticUse);
968
Jamie Madillf6be8d72014-09-05 10:38:07 -0400969 PixelShaderOutputVariable outputKeyVariable;
Geoff Lang04fb89a2014-06-09 15:05:36 -0400970 outputKeyVariable.type = outputVariable.type;
971 outputKeyVariable.name = variableName + elementString;
972 outputKeyVariable.source = variableName + ArrayString(outputLocation.element);
Jamie Madill80a6fc02015-08-21 16:53:16 -0400973 outputKeyVariable.outputIndex = outputPair.first;
Geoff Lang04fb89a2014-06-09 15:05:36 -0400974
975 outPixelShaderKey->push_back(outputKeyVariable);
Jamie Madill5f562732014-02-14 16:41:24 -0500976 }
Geoff Lang04fb89a2014-06-09 15:05:36 -0400977
978 *outUsesFragDepth = false;
Jamie Madill5f562732014-02-14 16:41:24 -0500979 }
980
Geoff Lang04fb89a2014-06-09 15:05:36 -0400981 pixelHLSL += PIXEL_OUTPUT_STUB_STRING + "\n";
Jamie Madill5f562732014-02-14 16:41:24 -0500982
Brandon Jones71620962014-08-20 14:04:59 -0700983 if (fragmentShader->mUsesFrontFacing)
Jamie Madill5f562732014-02-14 16:41:24 -0500984 {
985 if (shaderModel >= 4)
986 {
987 pixelHLSL += "PS_OUTPUT main(PS_INPUT input, bool isFrontFace : SV_IsFrontFace)\n"
988 "{\n";
989 }
990 else
991 {
992 pixelHLSL += "PS_OUTPUT main(PS_INPUT input, float vFace : VFACE)\n"
993 "{\n";
994 }
995 }
996 else
997 {
998 pixelHLSL += "PS_OUTPUT main(PS_INPUT input)\n"
999 "{\n";
1000 }
1001
Jamie Madillfebb7ad2014-06-18 13:50:51 -04001002 if (usesFragCoord)
Jamie Madill5f562732014-02-14 16:41:24 -05001003 {
1004 pixelHLSL += " float rhw = 1.0 / input.gl_FragCoord.w;\n";
1005
Austin Kinross588434c2014-12-10 10:41:45 -08001006 // Certain Shader Models (4_0+ and 3_0) allow reading from dx_Position in the pixel shader.
1007 // Other Shader Models (4_0_level_9_3 and 2_x) don't support this, so we emulate it using dx_ViewCoords.
1008 if (shaderModel >= 4 && mRenderer->getShaderModelSuffix() == "")
Jamie Madill5f562732014-02-14 16:41:24 -05001009 {
Jamie Madillfebb7ad2014-06-18 13:50:51 -04001010 pixelHLSL += " gl_FragCoord.x = input.dx_Position.x;\n"
1011 " gl_FragCoord.y = input.dx_Position.y;\n";
Jamie Madill5f562732014-02-14 16:41:24 -05001012 }
Austin Kinross588434c2014-12-10 10:41:45 -08001013 else if (shaderModel == 3)
Jamie Madill5f562732014-02-14 16:41:24 -05001014 {
Jamie Madillfebb7ad2014-06-18 13:50:51 -04001015 pixelHLSL += " gl_FragCoord.x = input.dx_Position.x + 0.5;\n"
1016 " gl_FragCoord.y = input.dx_Position.y + 0.5;\n";
Jamie Madill5f562732014-02-14 16:41:24 -05001017 }
1018 else
1019 {
1020 // dx_ViewCoords contains the viewport width/2, height/2, center.x and center.y. See Renderer::setViewport()
1021 pixelHLSL += " gl_FragCoord.x = (input.gl_FragCoord.x * rhw) * dx_ViewCoords.x + dx_ViewCoords.z;\n"
1022 " gl_FragCoord.y = (input.gl_FragCoord.y * rhw) * dx_ViewCoords.y + dx_ViewCoords.w;\n";
1023 }
1024
1025 pixelHLSL += " gl_FragCoord.z = (input.gl_FragCoord.z * rhw) * dx_DepthFront.x + dx_DepthFront.y;\n"
1026 " gl_FragCoord.w = rhw;\n";
1027 }
1028
Jamie Madillfebb7ad2014-06-18 13:50:51 -04001029 if (usesPointCoord && shaderModel >= 3)
Jamie Madill5f562732014-02-14 16:41:24 -05001030 {
1031 pixelHLSL += " gl_PointCoord.x = input.gl_PointCoord.x;\n";
1032 pixelHLSL += " gl_PointCoord.y = 1.0 - input.gl_PointCoord.y;\n";
1033 }
1034
Brandon Jones71620962014-08-20 14:04:59 -07001035 if (fragmentShader->mUsesFrontFacing)
Jamie Madill5f562732014-02-14 16:41:24 -05001036 {
1037 if (shaderModel <= 3)
1038 {
1039 pixelHLSL += " gl_FrontFacing = (vFace * dx_DepthFront.z >= 0.0);\n";
1040 }
1041 else
1042 {
1043 pixelHLSL += " gl_FrontFacing = isFrontFace;\n";
1044 }
1045 }
1046
Jamie Madillca03b352015-09-02 12:38:13 -04001047 for (const PackedVarying &packedVarying : packedVaryings)
Jamie Madill5f562732014-02-14 16:41:24 -05001048 {
Jamie Madill4cff2472015-08-21 16:53:18 -04001049 const sh::Varying &varying = *packedVarying.varying;
1050
1051 if (!packedVarying.registerAssigned())
Jamie Madill5f562732014-02-14 16:41:24 -05001052 {
Jamie Madill4cff2472015-08-21 16:53:18 -04001053 ASSERT(varying.isBuiltIn() || !varying.staticUse);
1054 continue;
1055 }
1056
Jamie Madillca03b352015-09-02 12:38:13 -04001057 // Don't reference VS-only transform feedback varyings in the PS.
1058 if (packedVarying.vertexOnly)
1059 continue;
1060
Jamie Madill4cff2472015-08-21 16:53:18 -04001061 ASSERT(!varying.isBuiltIn());
1062 for (unsigned int elementIndex = 0; elementIndex < varying.elementCount(); elementIndex++)
1063 {
1064 GLenum transposedType = TransposeMatrixType(varying.type);
1065 int variableRows = (varying.isStruct() ? 1 : VariableRowCount(transposedType));
1066 for (int row = 0; row < variableRows; row++)
Jamie Madill5f562732014-02-14 16:41:24 -05001067 {
Jamie Madill4cff2472015-08-21 16:53:18 -04001068 std::string n = Str(packedVarying.registerIndex +
1069 packedVarying.columnIndex * data.caps->maxVaryingVectors +
1070 elementIndex * variableRows + row);
1071 pixelHLSL += " _" + varying.name;
1072
1073 if (varying.isArray())
Jamie Madill5f562732014-02-14 16:41:24 -05001074 {
Jamie Madill4cff2472015-08-21 16:53:18 -04001075 pixelHLSL += ArrayString(elementIndex);
1076 }
Jamie Madill5f562732014-02-14 16:41:24 -05001077
Jamie Madill4cff2472015-08-21 16:53:18 -04001078 if (variableRows > 1)
1079 {
1080 pixelHLSL += ArrayString(row);
1081 }
Jamie Madill5f562732014-02-14 16:41:24 -05001082
Jamie Madill4cff2472015-08-21 16:53:18 -04001083 if (varying.isStruct())
1084 {
1085 pixelHLSL += " = input.v" + n + ";\n";
1086 break;
1087 }
1088 else
1089 {
1090 switch (VariableColumnCount(transposedType))
Jamie Madill5f562732014-02-14 16:41:24 -05001091 {
Jamie Madill4cff2472015-08-21 16:53:18 -04001092 case 1:
1093 pixelHLSL += " = input.v" + n + ".x;\n";
1094 break;
1095 case 2:
1096 pixelHLSL += " = input.v" + n + ".xy;\n";
1097 break;
1098 case 3:
1099 pixelHLSL += " = input.v" + n + ".xyz;\n";
1100 break;
1101 case 4:
1102 pixelHLSL += " = input.v" + n + ";\n";
1103 break;
1104 default:
1105 UNREACHABLE();
Jamie Madill5f562732014-02-14 16:41:24 -05001106 }
1107 }
1108 }
1109 }
Jamie Madill5f562732014-02-14 16:41:24 -05001110 }
1111
Jamie Madill37997142015-01-28 10:06:34 -05001112 if (fragmentShader->usesDeferredInit())
1113 {
1114 pixelHLSL += "\n"
1115 " initializeDeferredGlobals();\n";
1116 }
1117
Jamie Madill5f562732014-02-14 16:41:24 -05001118 pixelHLSL += "\n"
1119 " gl_main();\n"
1120 "\n"
Geoff Lang04fb89a2014-06-09 15:05:36 -04001121 " return generateOutput();\n"
Jamie Madill5f562732014-02-14 16:41:24 -05001122 "}\n";
1123
1124 return true;
1125}
1126
Jamie Madillca03b352015-09-02 12:38:13 -04001127std::string DynamicHLSL::generateGeometryShaderHLSL(
1128 int registers,
1129 const ShaderD3D *fragmentShader,
1130 const std::vector<PackedVarying> &packedVaryings) const
Jamie Madill5f562732014-02-14 16:41:24 -05001131{
1132 // for now we only handle point sprite emulation
Jamie Madillca03b352015-09-02 12:38:13 -04001133 ASSERT(mRenderer->getMajorShaderModel() >= 4);
1134 return generatePointSpriteHLSL(registers, fragmentShader, packedVaryings);
Jamie Madill5f562732014-02-14 16:41:24 -05001135}
1136
Jamie Madillca03b352015-09-02 12:38:13 -04001137std::string DynamicHLSL::generatePointSpriteHLSL(
1138 int registers,
1139 const ShaderD3D *fragmentShader,
1140 const std::vector<PackedVarying> &packedVaryings) const
Jamie Madill5f562732014-02-14 16:41:24 -05001141{
1142 ASSERT(registers >= 0);
Jamie Madill5f562732014-02-14 16:41:24 -05001143 ASSERT(mRenderer->getMajorShaderModel() >= 4);
1144
1145 std::string geomHLSL;
1146
Austin Kinross8b695ee2015-03-12 13:12:20 -07001147 const SemanticInfo &inSemantics = getSemanticInfo(registers, true, fragmentShader->mUsesFragCoord,
Jamie Madillfebb7ad2014-06-18 13:50:51 -04001148 false, true, false);
Austin Kinross8b695ee2015-03-12 13:12:20 -07001149 const SemanticInfo &outSemantics = getSemanticInfo(registers, true, fragmentShader->mUsesFragCoord,
Brandon Jones71620962014-08-20 14:04:59 -07001150 fragmentShader->mUsesPointCoord, true, false);
Jamie Madill5f562732014-02-14 16:41:24 -05001151
Jamie Madillca03b352015-09-02 12:38:13 -04001152 // If we're generating the geometry shader, we assume the vertex shader uses point size.
1153 std::string varyingHLSL = generateVaryingHLSL(packedVaryings, true);
Jamie Madillfebb7ad2014-06-18 13:50:51 -04001154 std::string inLinkHLSL = generateVaryingLinkHLSL(inSemantics, varyingHLSL);
1155 std::string outLinkHLSL = generateVaryingLinkHLSL(outSemantics, varyingHLSL);
Jamie Madill5f562732014-02-14 16:41:24 -05001156
Geoff Langc0b9ef42014-07-02 10:02:37 -04001157 // TODO(geofflang): use context's caps
Jamie Madill5f562732014-02-14 16:41:24 -05001158 geomHLSL += "uniform float4 dx_ViewCoords : register(c1);\n"
1159 "\n"
Jamie Madillfebb7ad2014-06-18 13:50:51 -04001160 "struct GS_INPUT\n" + inLinkHLSL + "\n" +
1161 "struct GS_OUTPUT\n" + outLinkHLSL + "\n" +
Jamie Madill5f562732014-02-14 16:41:24 -05001162 "\n"
Jamie Madill37997142015-01-28 10:06:34 -05001163 "static float2 pointSpriteCorners[] = \n"
1164 "{\n"
1165 " float2( 0.5f, -0.5f),\n"
1166 " float2( 0.5f, 0.5f),\n"
1167 " float2(-0.5f, -0.5f),\n"
1168 " float2(-0.5f, 0.5f)\n"
1169 "};\n"
1170 "\n"
1171 "static float2 pointSpriteTexcoords[] = \n"
1172 "{\n"
1173 " float2(1.0f, 1.0f),\n"
1174 " float2(1.0f, 0.0f),\n"
1175 " float2(0.0f, 1.0f),\n"
1176 " float2(0.0f, 0.0f)\n"
1177 "};\n"
1178 "\n"
Minmin Gong794e0002015-04-07 18:31:54 -07001179 "static float minPointSize = " + Str(static_cast<int>(mRenderer->getRendererCaps().minAliasedPointSize)) + ".0f;\n"
1180 "static float maxPointSize = " + Str(static_cast<int>(mRenderer->getRendererCaps().maxAliasedPointSize)) + ".0f;\n"
Jamie Madill37997142015-01-28 10:06:34 -05001181 "\n"
1182 "[maxvertexcount(4)]\n"
1183 "void main(point GS_INPUT input[1], inout TriangleStream<GS_OUTPUT> outStream)\n"
1184 "{\n"
1185 " GS_OUTPUT output = (GS_OUTPUT)0;\n"
1186 " output.gl_Position = input[0].gl_Position;\n"
1187 " output.gl_PointSize = input[0].gl_PointSize;\n";
Jamie Madill5f562732014-02-14 16:41:24 -05001188
1189 for (int r = 0; r < registers; r++)
1190 {
1191 geomHLSL += " output.v" + Str(r) + " = input[0].v" + Str(r) + ";\n";
1192 }
1193
Brandon Jones71620962014-08-20 14:04:59 -07001194 if (fragmentShader->mUsesFragCoord)
Jamie Madill5f562732014-02-14 16:41:24 -05001195 {
1196 geomHLSL += " output.gl_FragCoord = input[0].gl_FragCoord;\n";
1197 }
1198
1199 geomHLSL += " \n"
1200 " float gl_PointSize = clamp(input[0].gl_PointSize, minPointSize, maxPointSize);\n"
Jamie Madillfebb7ad2014-06-18 13:50:51 -04001201 " float4 dx_Position = input[0].dx_Position;\n"
1202 " float2 viewportScale = float2(1.0f / dx_ViewCoords.x, 1.0f / dx_ViewCoords.y) * dx_Position.w;\n";
Jamie Madill5f562732014-02-14 16:41:24 -05001203
1204 for (int corner = 0; corner < 4; corner++)
1205 {
1206 geomHLSL += " \n"
Jamie Madillfebb7ad2014-06-18 13:50:51 -04001207 " output.dx_Position = dx_Position + float4(pointSpriteCorners[" + Str(corner) + "] * viewportScale * gl_PointSize, 0.0f, 0.0f);\n";
Jamie Madill5f562732014-02-14 16:41:24 -05001208
Brandon Jones71620962014-08-20 14:04:59 -07001209 if (fragmentShader->mUsesPointCoord)
Jamie Madill5f562732014-02-14 16:41:24 -05001210 {
1211 geomHLSL += " output.gl_PointCoord = pointSpriteTexcoords[" + Str(corner) + "];\n";
1212 }
1213
1214 geomHLSL += " outStream.Append(output);\n";
1215 }
1216
1217 geomHLSL += " \n"
1218 " outStream.RestartStrip();\n"
1219 "}\n";
1220
1221 return geomHLSL;
1222}
1223
1224// This method needs to match OutputHLSL::decorate
Jamie Madilla53ab512014-03-17 09:47:44 -04001225std::string DynamicHLSL::decorateVariable(const std::string &name)
Jamie Madill5f562732014-02-14 16:41:24 -05001226{
Jamie Madilld5512cd2014-07-10 17:50:08 -04001227 if (name.compare(0, 3, "gl_") != 0)
Jamie Madill5f562732014-02-14 16:41:24 -05001228 {
1229 return "_" + name;
1230 }
1231
1232 return name;
1233}
1234
Jamie Madilld3dfda22015-07-06 08:28:49 -04001235std::string DynamicHLSL::generateAttributeConversionHLSL(gl::VertexFormatType vertexFormatType,
1236 const sh::ShaderVariable &shaderAttrib) const
Jamie Madillc5ede1a2014-02-14 16:41:27 -05001237{
Jamie Madilld3dfda22015-07-06 08:28:49 -04001238 const gl::VertexFormat &vertexFormat = gl::GetVertexFormatFromType(vertexFormatType);
Jamie Madilla53ab512014-03-17 09:47:44 -04001239 std::string attribString = "input." + decorateVariable(shaderAttrib.name);
Jamie Madill8664b062014-02-14 16:41:29 -05001240
Jamie Madillc5ede1a2014-02-14 16:41:27 -05001241 // Matrix
1242 if (IsMatrixType(shaderAttrib.type))
1243 {
Jamie Madill8664b062014-02-14 16:41:29 -05001244 return "transpose(" + attribString + ")";
Jamie Madillc5ede1a2014-02-14 16:41:27 -05001245 }
1246
Jamie Madillf2575982014-06-25 16:04:54 -04001247 GLenum shaderComponentType = VariableComponentType(shaderAttrib.type);
1248 int shaderComponentCount = VariableComponentCount(shaderAttrib.type);
Jamie Madill8664b062014-02-14 16:41:29 -05001249
Jamie Madill8664b062014-02-14 16:41:29 -05001250 // Perform integer to float conversion (if necessary)
Jamie Madilld3dfda22015-07-06 08:28:49 -04001251 bool requiresTypeConversion = (shaderComponentType == GL_FLOAT && vertexFormat.type != GL_FLOAT);
Jamie Madill8664b062014-02-14 16:41:29 -05001252
Jamie Madill7a29e4a2014-05-02 10:41:48 -04001253 if (requiresTypeConversion)
Jamie Madill8664b062014-02-14 16:41:29 -05001254 {
Jamie Madill7a29e4a2014-05-02 10:41:48 -04001255 // TODO: normalization for 32-bit integer formats
Jamie Madilld3dfda22015-07-06 08:28:49 -04001256 ASSERT(!vertexFormat.normalized && !vertexFormat.pureInteger);
Jamie Madill7a29e4a2014-05-02 10:41:48 -04001257 return "float" + Str(shaderComponentCount) + "(" + attribString + ")";
Jamie Madill8664b062014-02-14 16:41:29 -05001258 }
Jamie Madillc5ede1a2014-02-14 16:41:27 -05001259
1260 // No conversion necessary
Jamie Madill8664b062014-02-14 16:41:29 -05001261 return attribString;
Jamie Madillc5ede1a2014-02-14 16:41:27 -05001262}
1263
Jamie Madill5f562732014-02-14 16:41:24 -05001264}