blob: 193fca51a60cfcaa3c9d5b7f3c5e42da2e83ba5e [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
9#include "precompiled.h"
10
11#include "libGLESv2/DynamicHLSL.h"
12#include "libGLESv2/Shader.h"
13#include "libGLESv2/Program.h"
14#include "libGLESv2/renderer/Renderer.h"
15#include "common/utilities.h"
16#include "libGLESv2/ProgramBinary.h"
Jamie Madill8664b062014-02-14 16:41:29 -050017#include "libGLESv2/formatutils.h"
Jamie Madill834e8b72014-04-11 13:33:58 -040018#include "common/blocklayout.h"
Jamie Madill5f562732014-02-14 16:41:24 -050019
Jamie Madill5f562732014-02-14 16:41:24 -050020static std::string Str(int i)
21{
22 char buffer[20];
23 snprintf(buffer, sizeof(buffer), "%d", i);
24 return buffer;
25}
26
Jamie Madill8664b062014-02-14 16:41:29 -050027namespace gl_d3d
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
72 return HLSLComponentTypeString(gl::UniformComponentType(type), gl::UniformComponentCount(type));
73}
74
75}
76
77namespace gl
78{
79
Jamie Madill5f562732014-02-14 16:41:24 -050080std::string ArrayString(unsigned int i)
81{
82 return (i == GL_INVALID_INDEX ? "" : "[" + Str(i) + "]");
83}
84
Jamie Madillc5ede1a2014-02-14 16:41:27 -050085const std::string DynamicHLSL::VERTEX_ATTRIBUTE_STUB_STRING = "@@ VERTEX ATTRIBUTES @@";
86
Jamie Madill5f562732014-02-14 16:41:24 -050087DynamicHLSL::DynamicHLSL(rx::Renderer *const renderer)
88 : mRenderer(renderer)
89{
90}
91
Jamie Madill834e8b72014-04-11 13:33:58 -040092static bool packVarying(Varying *varying, const int maxVaryingVectors, const ShaderVariable *packing[][4])
Jamie Madill5f562732014-02-14 16:41:24 -050093{
Geoff Lang48dcae72014-02-05 16:28:24 -050094 GLenum transposedType = TransposeMatrixType(varying->type);
Jamie Madill5f562732014-02-14 16:41:24 -050095
Geoff Lang48dcae72014-02-05 16:28:24 -050096 // matrices within varying structs are not transposed
Jamie Madill834e8b72014-04-11 13:33:58 -040097 int registers = (varying->isStruct() ? HLSLVariableRegisterCount(*varying) : VariableRowCount(transposedType)) * varying->elementCount();
Geoff Lang48dcae72014-02-05 16:28:24 -050098 int elements = (varying->isStruct() ? 4 : VariableColumnCount(transposedType));
99 bool success = false;
Jamie Madill5f562732014-02-14 16:41:24 -0500100
Geoff Lang48dcae72014-02-05 16:28:24 -0500101 if (elements == 2 || elements == 3 || elements == 4)
Jamie Madill5f562732014-02-14 16:41:24 -0500102 {
Geoff Lang48dcae72014-02-05 16:28:24 -0500103 for (int r = 0; r <= maxVaryingVectors - registers && !success; r++)
Jamie Madill5f562732014-02-14 16:41:24 -0500104 {
Geoff Lang48dcae72014-02-05 16:28:24 -0500105 bool available = true;
106
107 for (int y = 0; y < registers && available; y++)
108 {
109 for (int x = 0; x < elements && available; x++)
110 {
111 if (packing[r + y][x])
112 {
113 available = false;
114 }
115 }
116 }
117
118 if (available)
119 {
120 varying->registerIndex = r;
121 varying->elementIndex = 0;
122
123 for (int y = 0; y < registers; y++)
124 {
125 for (int x = 0; x < elements; x++)
126 {
127 packing[r + y][x] = &*varying;
128 }
129 }
130
131 success = true;
132 }
133 }
134
135 if (!success && elements == 2)
136 {
137 for (int r = maxVaryingVectors - registers; r >= 0 && !success; r--)
Jamie Madill5f562732014-02-14 16:41:24 -0500138 {
139 bool available = true;
140
141 for (int y = 0; y < registers && available; y++)
142 {
Geoff Lang48dcae72014-02-05 16:28:24 -0500143 for (int x = 2; x < 4 && available; x++)
Jamie Madill5f562732014-02-14 16:41:24 -0500144 {
145 if (packing[r + y][x])
146 {
147 available = false;
148 }
149 }
150 }
151
152 if (available)
153 {
154 varying->registerIndex = r;
Geoff Lang48dcae72014-02-05 16:28:24 -0500155 varying->elementIndex = 2;
Jamie Madill5f562732014-02-14 16:41:24 -0500156
157 for (int y = 0; y < registers; y++)
158 {
Geoff Lang48dcae72014-02-05 16:28:24 -0500159 for (int x = 2; x < 4; x++)
Jamie Madill5f562732014-02-14 16:41:24 -0500160 {
161 packing[r + y][x] = &*varying;
162 }
163 }
164
165 success = true;
166 }
167 }
Jamie Madill5f562732014-02-14 16:41:24 -0500168 }
Geoff Lang48dcae72014-02-05 16:28:24 -0500169 }
170 else if (elements == 1)
171 {
172 int space[4] = { 0 };
173
174 for (int y = 0; y < maxVaryingVectors; y++)
Jamie Madill5f562732014-02-14 16:41:24 -0500175 {
Jamie Madill5f562732014-02-14 16:41:24 -0500176 for (int x = 0; x < 4; x++)
177 {
Geoff Lang48dcae72014-02-05 16:28:24 -0500178 space[x] += packing[y][x] ? 0 : 1;
Jamie Madill5f562732014-02-14 16:41:24 -0500179 }
180 }
Jamie Madill5f562732014-02-14 16:41:24 -0500181
Geoff Lang48dcae72014-02-05 16:28:24 -0500182 int column = 0;
183
184 for (int x = 0; x < 4; x++)
185 {
186 if (space[x] >= registers && space[x] < space[column])
187 {
188 column = x;
189 }
190 }
191
192 if (space[column] >= registers)
193 {
194 for (int r = 0; r < maxVaryingVectors; r++)
195 {
196 if (!packing[r][column])
197 {
198 varying->registerIndex = r;
199
200 for (int y = r; y < r + registers; y++)
201 {
202 packing[y][column] = &*varying;
203 }
204
205 break;
206 }
207 }
208
209 varying->elementIndex = column;
210
211 success = true;
212 }
213 }
214 else UNREACHABLE();
215
216 return success;
217}
218
219// Packs varyings into generic varying registers, using the algorithm from [OpenGL ES Shading Language 1.00 rev. 17] appendix A section 7 page 111
220// Returns the number of used varying registers, or -1 if unsuccesful
Jamie Madill834e8b72014-04-11 13:33:58 -0400221int DynamicHLSL::packVaryings(InfoLog &infoLog, const ShaderVariable *packing[][4], FragmentShader *fragmentShader,
Geoff Lang48dcae72014-02-05 16:28:24 -0500222 VertexShader *vertexShader, const std::vector<std::string>& transformFeedbackVaryings)
223{
224 const int maxVaryingVectors = mRenderer->getMaxVaryingVectors();
225
226 vertexShader->resetVaryingsRegisterAssignment();
227 fragmentShader->resetVaryingsRegisterAssignment();
228
229 std::set<std::string> packedVaryings;
230
231 for (unsigned int varyingIndex = 0; varyingIndex < fragmentShader->mVaryings.size(); varyingIndex++)
232 {
Jamie Madill834e8b72014-04-11 13:33:58 -0400233 Varying *varying = &fragmentShader->mVaryings[varyingIndex];
Geoff Lang48dcae72014-02-05 16:28:24 -0500234 if (packVarying(varying, maxVaryingVectors, packing))
235 {
236 packedVaryings.insert(varying->name);
237 }
238 else
Jamie Madill5f562732014-02-14 16:41:24 -0500239 {
240 infoLog.append("Could not pack varying %s", varying->name.c_str());
Jamie Madill5f562732014-02-14 16:41:24 -0500241 return -1;
242 }
243 }
244
Geoff Lang48dcae72014-02-05 16:28:24 -0500245 for (unsigned int feedbackVaryingIndex = 0; feedbackVaryingIndex < transformFeedbackVaryings.size(); feedbackVaryingIndex++)
246 {
247 const std::string &transformFeedbackVarying = transformFeedbackVaryings[feedbackVaryingIndex];
248 if (packedVaryings.find(transformFeedbackVarying) == packedVaryings.end())
249 {
250 bool found = false;
251 for (unsigned int varyingIndex = 0; varyingIndex < vertexShader->mVaryings.size(); varyingIndex++)
252 {
Jamie Madill834e8b72014-04-11 13:33:58 -0400253 Varying *varying = &vertexShader->mVaryings[varyingIndex];
Geoff Lang48dcae72014-02-05 16:28:24 -0500254 if (transformFeedbackVarying == varying->name)
255 {
256 if (!packVarying(varying, maxVaryingVectors, packing))
257 {
258 infoLog.append("Could not pack varying %s", varying->name.c_str());
259 return -1;
260 }
261
262 found = true;
263 break;
264 }
265 }
266
267 if (!found && transformFeedbackVarying != "gl_Position" && transformFeedbackVarying != "gl_PointSize")
268 {
269 infoLog.append("Transform feedback varying %s does not exist in the vertex shader.", transformFeedbackVarying.c_str());
270 return -1;
271 }
272 }
273 }
274
Jamie Madill5f562732014-02-14 16:41:24 -0500275 // Return the number of used registers
276 int registers = 0;
277
278 for (int r = 0; r < maxVaryingVectors; r++)
279 {
280 if (packing[r][0] || packing[r][1] || packing[r][2] || packing[r][3])
281 {
282 registers++;
283 }
284 }
285
286 return registers;
287}
288
Geoff Lang48dcae72014-02-05 16:28:24 -0500289std::string DynamicHLSL::generateVaryingHLSL(VertexShader *shader, const std::string &varyingSemantic,
290 std::vector<LinkedVarying> *linkedVaryings) const
Jamie Madill5f562732014-02-14 16:41:24 -0500291{
292 std::string varyingHLSL;
293
Geoff Lang48dcae72014-02-05 16:28:24 -0500294 for (unsigned int varyingIndex = 0; varyingIndex < shader->mVaryings.size(); varyingIndex++)
Jamie Madill5f562732014-02-14 16:41:24 -0500295 {
Jamie Madill834e8b72014-04-11 13:33:58 -0400296 Varying *varying = &shader->mVaryings[varyingIndex];
Jamie Madill5f562732014-02-14 16:41:24 -0500297 if (varying->registerAssigned())
298 {
Geoff Lang48dcae72014-02-05 16:28:24 -0500299 GLenum transposedType = TransposeMatrixType(varying->type);
300 int variableRows = (varying->isStruct() ? 1 : VariableRowCount(transposedType));
301
Jamie Madill5f562732014-02-14 16:41:24 -0500302 for (unsigned int elementIndex = 0; elementIndex < varying->elementCount(); elementIndex++)
303 {
Jamie Madill5f562732014-02-14 16:41:24 -0500304 for (int row = 0; row < variableRows; row++)
305 {
306 switch (varying->interpolation)
307 {
Jamie Madill834e8b72014-04-11 13:33:58 -0400308 case INTERPOLATION_SMOOTH: varyingHLSL += " "; break;
309 case INTERPOLATION_FLAT: varyingHLSL += " nointerpolation "; break;
310 case INTERPOLATION_CENTROID: varyingHLSL += " centroid "; break;
Jamie Madill5f562732014-02-14 16:41:24 -0500311 default: UNREACHABLE();
312 }
313
Geoff Lang48dcae72014-02-05 16:28:24 -0500314 unsigned int semanticIndex = elementIndex * variableRows + varying->registerIndex + row;
315 std::string n = Str(semanticIndex);
Jamie Madill5f562732014-02-14 16:41:24 -0500316
Jamie Madilla53ab512014-03-17 09:47:44 -0400317 std::string typeString;
318
319 if (varying->isStruct())
320 {
321 // matrices within structs are not transposed, so
322 // do not use the special struct prefix "rm"
323 typeString = decorateVariable(varying->structName);
324 }
325 else
326 {
Jamie Madill834e8b72014-04-11 13:33:58 -0400327 GLenum componentType = UniformComponentType(transposedType);
328 int columnCount = VariableColumnCount(transposedType);
Jamie Madilla53ab512014-03-17 09:47:44 -0400329 typeString = gl_d3d::HLSLComponentTypeString(componentType, columnCount);
330 }
Jamie Madill5f562732014-02-14 16:41:24 -0500331 varyingHLSL += typeString + " v" + n + " : " + varyingSemantic + n + ";\n";
332 }
333 }
Geoff Lang48dcae72014-02-05 16:28:24 -0500334
335 if (linkedVaryings)
336 {
337 linkedVaryings->push_back(LinkedVarying(varying->name, varying->type, varying->elementCount(),
338 varyingSemantic, varying->registerIndex,
339 variableRows * varying->elementCount()));
340 }
Jamie Madill5f562732014-02-14 16:41:24 -0500341 }
Jamie Madill5f562732014-02-14 16:41:24 -0500342 }
343
344 return varyingHLSL;
345}
346
Jamie Madill834e8b72014-04-11 13:33:58 -0400347std::string DynamicHLSL::generateInputLayoutHLSL(const VertexFormat inputLayout[], const Attribute shaderAttributes[]) const
Jamie Madillc5ede1a2014-02-14 16:41:27 -0500348{
Jamie Madill3b7e2052014-03-17 09:47:43 -0400349 std::string structHLSL, initHLSL;
Jamie Madillc5ede1a2014-02-14 16:41:27 -0500350
351 int semanticIndex = 0;
Jamie Madill3b7e2052014-03-17 09:47:43 -0400352 unsigned int inputIndex = 0;
353
Jamie Madillc5ede1a2014-02-14 16:41:27 -0500354 for (unsigned int attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++)
355 {
Jamie Madill3b7e2052014-03-17 09:47:43 -0400356 ASSERT(inputIndex < MAX_VERTEX_ATTRIBS);
357
358 const VertexFormat &vertexFormat = inputLayout[inputIndex];
Jamie Madill834e8b72014-04-11 13:33:58 -0400359 const Attribute &shaderAttribute = shaderAttributes[attributeIndex];
Jamie Madillc5ede1a2014-02-14 16:41:27 -0500360
Jamie Madill8664b062014-02-14 16:41:29 -0500361 if (!shaderAttribute.name.empty())
Jamie Madillc5ede1a2014-02-14 16:41:27 -0500362 {
Jamie Madill3b7e2052014-03-17 09:47:43 -0400363 // HLSL code for input structure
Jamie Madill8664b062014-02-14 16:41:29 -0500364 if (IsMatrixType(shaderAttribute.type))
365 {
366 // Matrix types are always transposed
Jamie Madill3b7e2052014-03-17 09:47:43 -0400367 structHLSL += " " + gl_d3d::HLSLMatrixTypeString(TransposeMatrixType(shaderAttribute.type));
Jamie Madill8664b062014-02-14 16:41:29 -0500368 }
369 else
370 {
371 GLenum componentType = mRenderer->getVertexComponentType(vertexFormat);
Jamie Madill3b7e2052014-03-17 09:47:43 -0400372 structHLSL += " " + gl_d3d::HLSLComponentTypeString(componentType, UniformComponentCount(shaderAttribute.type));
Jamie Madill8664b062014-02-14 16:41:29 -0500373 }
Jamie Madillc5ede1a2014-02-14 16:41:27 -0500374
Jamie Madilla53ab512014-03-17 09:47:44 -0400375 structHLSL += " " + decorateVariable(shaderAttribute.name) + " : TEXCOORD" + Str(semanticIndex) + ";\n";
Jamie Madill8664b062014-02-14 16:41:29 -0500376 semanticIndex += AttributeRegisterCount(shaderAttribute.type);
Jamie Madillc5ede1a2014-02-14 16:41:27 -0500377
Jamie Madill3b7e2052014-03-17 09:47:43 -0400378 // HLSL code for initialization
Jamie Madilla53ab512014-03-17 09:47:44 -0400379 initHLSL += " " + decorateVariable(shaderAttribute.name) + " = ";
Jamie Madill8664b062014-02-14 16:41:29 -0500380
381 // Mismatched vertex attribute to vertex input may result in an undefined
382 // data reinterpretation (eg for pure integer->float, float->pure integer)
383 // TODO: issue warning with gl debug info extension, when supported
Jamie Madill3b7e2052014-03-17 09:47:43 -0400384 if (IsMatrixType(shaderAttribute.type) ||
385 (mRenderer->getVertexConversionType(vertexFormat) & rx::VERTEX_CONVERT_GPU) != 0)
Jamie Madill8664b062014-02-14 16:41:29 -0500386 {
Jamie Madill3b7e2052014-03-17 09:47:43 -0400387 initHLSL += generateAttributeConversionHLSL(vertexFormat, shaderAttribute);
Jamie Madill8664b062014-02-14 16:41:29 -0500388 }
389 else
390 {
Jamie Madilla53ab512014-03-17 09:47:44 -0400391 initHLSL += "input." + decorateVariable(shaderAttribute.name);
Jamie Madill8664b062014-02-14 16:41:29 -0500392 }
393
Jamie Madill3b7e2052014-03-17 09:47:43 -0400394 initHLSL += ";\n";
Jamie Madill3b7e2052014-03-17 09:47:43 -0400395
Jamie Madillac0a2672014-04-11 13:33:56 -0400396 inputIndex += VariableRowCount(TransposeMatrixType(shaderAttribute.type));
397 }
Jamie Madillc5ede1a2014-02-14 16:41:27 -0500398 }
399
Jamie Madill3b7e2052014-03-17 09:47:43 -0400400 return "struct VS_INPUT\n"
401 "{\n" +
402 structHLSL +
403 "};\n"
404 "\n"
405 "void initAttributes(VS_INPUT input)\n"
406 "{\n" +
407 initHLSL +
408 "}\n";
Jamie Madillc5ede1a2014-02-14 16:41:27 -0500409}
410
Jamie Madill834e8b72014-04-11 13:33:58 -0400411bool DynamicHLSL::generateShaderLinkHLSL(InfoLog &infoLog, int registers, const ShaderVariable *packing[][4],
Jamie Madill5f562732014-02-14 16:41:24 -0500412 std::string& pixelHLSL, std::string& vertexHLSL,
413 FragmentShader *fragmentShader, VertexShader *vertexShader,
Geoff Lang48dcae72014-02-05 16:28:24 -0500414 const std::vector<std::string>& transformFeedbackVaryings,
415 std::vector<LinkedVarying> *linkedVaryings,
Jamie Madill5f562732014-02-14 16:41:24 -0500416 std::map<int, VariableLocation> *programOutputVars) const
417{
418 if (pixelHLSL.empty() || vertexHLSL.empty())
419 {
420 return false;
421 }
422
423 bool usesMRT = fragmentShader->mUsesMultipleRenderTargets;
424 bool usesFragColor = fragmentShader->mUsesFragColor;
425 bool usesFragData = fragmentShader->mUsesFragData;
426 if (usesFragColor && usesFragData)
427 {
428 infoLog.append("Cannot use both gl_FragColor and gl_FragData in the same fragment shader.");
429 return false;
430 }
431
432 // Write the HLSL input/output declarations
433 const int shaderModel = mRenderer->getMajorShaderModel();
434 const int maxVaryingVectors = mRenderer->getMaxVaryingVectors();
435
436 const int registersNeeded = registers + (fragmentShader->mUsesFragCoord ? 1 : 0) + (fragmentShader->mUsesPointCoord ? 1 : 0);
437
438 // Two cases when writing to gl_FragColor and using ESSL 1.0:
439 // - with a 3.0 context, the output color is copied to channel 0
440 // - with a 2.0 context, the output color is broadcast to all channels
441 const bool broadcast = (fragmentShader->mUsesFragColor && mRenderer->getCurrentClientVersion() < 3);
442 const unsigned int numRenderTargets = (broadcast || usesMRT ? mRenderer->getMaxRenderTargets() : 1);
443
444 int shaderVersion = vertexShader->getShaderVersion();
445
446 if (registersNeeded > maxVaryingVectors)
447 {
448 infoLog.append("No varying registers left to support gl_FragCoord/gl_PointCoord");
449
450 return false;
451 }
452
453 std::string varyingSemantic = (vertexShader->mUsesPointSize && shaderModel == 3) ? "COLOR" : "TEXCOORD";
454 std::string targetSemantic = (shaderModel >= 4) ? "SV_Target" : "COLOR";
Geoff Lang48dcae72014-02-05 16:28:24 -0500455 std::string dxPositionSemantic = (shaderModel >= 4) ? "SV_Position" : "POSITION";
Jamie Madill5f562732014-02-14 16:41:24 -0500456 std::string depthSemantic = (shaderModel >= 4) ? "SV_Depth" : "DEPTH";
457
Geoff Lang48dcae72014-02-05 16:28:24 -0500458 std::string varyingHLSL = generateVaryingHLSL(vertexShader, varyingSemantic, linkedVaryings);
Jamie Madill5f562732014-02-14 16:41:24 -0500459
460 // special varyings that use reserved registers
461 int reservedRegisterIndex = registers;
Jamie Madill5f562732014-02-14 16:41:24 -0500462
Geoff Lang48dcae72014-02-05 16:28:24 -0500463 unsigned int glPositionSemanticIndex = reservedRegisterIndex++;
464 std::string glPositionSemantic = varyingSemantic;
465
466 std::string fragCoordSemantic;
467 unsigned int fragCoordSemanticIndex = 0;
Jamie Madill5f562732014-02-14 16:41:24 -0500468 if (fragmentShader->mUsesFragCoord)
469 {
Geoff Lang48dcae72014-02-05 16:28:24 -0500470 fragCoordSemanticIndex = reservedRegisterIndex++;
471 fragCoordSemantic = varyingSemantic;
Jamie Madill5f562732014-02-14 16:41:24 -0500472 }
473
Geoff Lang48dcae72014-02-05 16:28:24 -0500474 std::string pointCoordSemantic;
475 unsigned int pointCoordSemanticIndex = 0;
Jamie Madill5f562732014-02-14 16:41:24 -0500476 if (fragmentShader->mUsesPointCoord)
477 {
478 // Shader model 3 uses a special TEXCOORD semantic for point sprite texcoords.
479 // In DX11 we compute this in the GS.
480 if (shaderModel == 3)
481 {
Geoff Lang48dcae72014-02-05 16:28:24 -0500482 pointCoordSemanticIndex = 0;
Jamie Madill5f562732014-02-14 16:41:24 -0500483 pointCoordSemantic = "TEXCOORD0";
484 }
485 else if (shaderModel >= 4)
486 {
Geoff Lang48dcae72014-02-05 16:28:24 -0500487 pointCoordSemanticIndex = reservedRegisterIndex++;
488 pointCoordSemantic = varyingSemantic;
Jamie Madill5f562732014-02-14 16:41:24 -0500489 }
490 }
491
Jamie Madillc5ede1a2014-02-14 16:41:27 -0500492 // Add stub string to be replaced when shader is dynamically defined by its layout
493 vertexHLSL += "\n" + VERTEX_ATTRIBUTE_STUB_STRING + "\n";
Jamie Madill5f562732014-02-14 16:41:24 -0500494
Jamie Madillc5ede1a2014-02-14 16:41:27 -0500495 vertexHLSL += "struct VS_OUTPUT\n"
Jamie Madill5f562732014-02-14 16:41:24 -0500496 "{\n";
497
498 if (shaderModel < 4)
499 {
Geoff Lang48dcae72014-02-05 16:28:24 -0500500 vertexHLSL += " float4 _dx_Position : " + dxPositionSemantic + ";\n";
501 vertexHLSL += " float4 gl_Position : " + glPositionSemantic + Str(glPositionSemanticIndex) + ";\n";
502 linkedVaryings->push_back(LinkedVarying("gl_Position", GL_FLOAT_VEC4, 1, glPositionSemantic, glPositionSemanticIndex, 1));
503
Jamie Madill5f562732014-02-14 16:41:24 -0500504 }
505
506 vertexHLSL += varyingHLSL;
507
508 if (fragmentShader->mUsesFragCoord)
509 {
Geoff Lang48dcae72014-02-05 16:28:24 -0500510 vertexHLSL += " float4 gl_FragCoord : " + fragCoordSemantic + Str(fragCoordSemanticIndex) + ";\n";
511 linkedVaryings->push_back(LinkedVarying("gl_FragCoord", GL_FLOAT_VEC4, 1, fragCoordSemantic, fragCoordSemanticIndex, 1));
Jamie Madill5f562732014-02-14 16:41:24 -0500512 }
513
514 if (vertexShader->mUsesPointSize && shaderModel >= 3)
515 {
516 vertexHLSL += " float gl_PointSize : PSIZE;\n";
Geoff Lang48dcae72014-02-05 16:28:24 -0500517 linkedVaryings->push_back(LinkedVarying("gl_PointSize", GL_FLOAT, 1, "PSIZE", 0, 1));
Jamie Madill5f562732014-02-14 16:41:24 -0500518 }
519
520 if (shaderModel >= 4)
521 {
Geoff Lang48dcae72014-02-05 16:28:24 -0500522 vertexHLSL += " float4 _dx_Position : " + dxPositionSemantic + ";\n";
523 vertexHLSL += " float4 gl_Position : " + glPositionSemantic + Str(glPositionSemanticIndex) + ";\n";
524 linkedVaryings->push_back(LinkedVarying("gl_Position", GL_FLOAT_VEC4, 1, glPositionSemantic, glPositionSemanticIndex, 1));
Jamie Madill5f562732014-02-14 16:41:24 -0500525 }
526
527 vertexHLSL += "};\n"
528 "\n"
529 "VS_OUTPUT main(VS_INPUT input)\n"
Jamie Madillc5ede1a2014-02-14 16:41:27 -0500530 "{\n"
531 " initAttributes(input);\n";
Jamie Madill5f562732014-02-14 16:41:24 -0500532
533 if (shaderModel >= 4)
534 {
535 vertexHLSL += "\n"
536 " gl_main();\n"
537 "\n"
538 " VS_OUTPUT output;\n"
Geoff Lang48dcae72014-02-05 16:28:24 -0500539 " output.gl_Position = gl_Position;\n"
540 " output._dx_Position.x = gl_Position.x;\n"
541 " output._dx_Position.y = -gl_Position.y;\n"
542 " output._dx_Position.z = (gl_Position.z + gl_Position.w) * 0.5;\n"
543 " output._dx_Position.w = gl_Position.w;\n";
Jamie Madill5f562732014-02-14 16:41:24 -0500544 }
545 else
546 {
547 vertexHLSL += "\n"
548 " gl_main();\n"
549 "\n"
550 " VS_OUTPUT output;\n"
Geoff Lang48dcae72014-02-05 16:28:24 -0500551 " output.gl_Position = gl_Position;\n"
552 " output._dx_Position.x = gl_Position.x * dx_ViewAdjust.z + dx_ViewAdjust.x * gl_Position.w;\n"
553 " output._dx_Position.y = -(gl_Position.y * dx_ViewAdjust.w + dx_ViewAdjust.y * gl_Position.w);\n"
554 " output._dx_Position.z = (gl_Position.z + gl_Position.w) * 0.5;\n"
555 " output._dx_Position.w = gl_Position.w;\n";
Jamie Madill5f562732014-02-14 16:41:24 -0500556 }
557
558 if (vertexShader->mUsesPointSize && shaderModel >= 3)
559 {
560 vertexHLSL += " output.gl_PointSize = gl_PointSize;\n";
561 }
562
563 if (fragmentShader->mUsesFragCoord)
564 {
565 vertexHLSL += " output.gl_FragCoord = gl_Position;\n";
566 }
567
568 for (unsigned int vertVaryingIndex = 0; vertVaryingIndex < vertexShader->mVaryings.size(); vertVaryingIndex++)
569 {
Jamie Madill834e8b72014-04-11 13:33:58 -0400570 Varying *varying = &vertexShader->mVaryings[vertVaryingIndex];
Jamie Madill5f562732014-02-14 16:41:24 -0500571 if (varying->registerAssigned())
572 {
573 for (unsigned int elementIndex = 0; elementIndex < varying->elementCount(); elementIndex++)
574 {
575 int variableRows = (varying->isStruct() ? 1 : VariableRowCount(TransposeMatrixType(varying->type)));
576
577 for (int row = 0; row < variableRows; row++)
578 {
579 int r = varying->registerIndex + elementIndex * variableRows + row;
580 vertexHLSL += " output.v" + Str(r);
581
582 bool sharedRegister = false; // Register used by multiple varyings
583
584 for (int x = 0; x < 4; x++)
585 {
586 if (packing[r][x] && packing[r][x] != packing[r][0])
587 {
588 sharedRegister = true;
589 break;
590 }
591 }
592
593 if(sharedRegister)
594 {
595 vertexHLSL += ".";
596
597 for (int x = 0; x < 4; x++)
598 {
599 if (packing[r][x] == &*varying)
600 {
601 switch(x)
602 {
603 case 0: vertexHLSL += "x"; break;
604 case 1: vertexHLSL += "y"; break;
605 case 2: vertexHLSL += "z"; break;
606 case 3: vertexHLSL += "w"; break;
607 }
608 }
609 }
610 }
611
612 vertexHLSL += " = _" + varying->name;
613
614 if (varying->isArray())
615 {
616 vertexHLSL += ArrayString(elementIndex);
617 }
618
619 if (variableRows > 1)
620 {
621 vertexHLSL += ArrayString(row);
622 }
623
624 vertexHLSL += ";\n";
625 }
626 }
627 }
628 }
629
630 vertexHLSL += "\n"
631 " return output;\n"
632 "}\n";
633
634 pixelHLSL += "struct PS_INPUT\n"
635 "{\n";
636
637 pixelHLSL += varyingHLSL;
638
639 if (fragmentShader->mUsesFragCoord)
640 {
Geoff Langb5b02852014-04-16 14:39:36 -0400641 pixelHLSL += " float4 gl_FragCoord : " + fragCoordSemantic + Str(fragCoordSemanticIndex) + ";\n";
Jamie Madill5f562732014-02-14 16:41:24 -0500642 }
643
644 if (fragmentShader->mUsesPointCoord && shaderModel >= 3)
645 {
Geoff Lang48dcae72014-02-05 16:28:24 -0500646 pixelHLSL += " float2 gl_PointCoord : " + pointCoordSemantic + Str(pointCoordSemanticIndex) + ";\n";
Jamie Madill5f562732014-02-14 16:41:24 -0500647 }
648
649 // Must consume the PSIZE element if the geometry shader is not active
650 // We won't know if we use a GS until we draw
651 if (vertexShader->mUsesPointSize && shaderModel >= 4)
652 {
653 pixelHLSL += " float gl_PointSize : PSIZE;\n";
654 }
655
656 if (fragmentShader->mUsesFragCoord)
657 {
658 if (shaderModel >= 4)
659 {
660 pixelHLSL += " float4 dx_VPos : SV_Position;\n";
661 }
662 else if (shaderModel >= 3)
663 {
664 pixelHLSL += " float2 dx_VPos : VPOS;\n";
665 }
666 }
667
668 pixelHLSL += "};\n"
669 "\n"
670 "struct PS_OUTPUT\n"
671 "{\n";
672
673 if (shaderVersion < 300)
674 {
675 for (unsigned int renderTargetIndex = 0; renderTargetIndex < numRenderTargets; renderTargetIndex++)
676 {
677 pixelHLSL += " float4 gl_Color" + Str(renderTargetIndex) + " : " + targetSemantic + Str(renderTargetIndex) + ";\n";
678 }
679
680 if (fragmentShader->mUsesFragDepth)
681 {
682 pixelHLSL += " float gl_Depth : " + depthSemantic + ";\n";
683 }
684 }
685 else
686 {
687 defineOutputVariables(fragmentShader, programOutputVars);
688
Jamie Madill834e8b72014-04-11 13:33:58 -0400689 const std::vector<Attribute> &shaderOutputVars = fragmentShader->getOutputVariables();
Jamie Madill5f562732014-02-14 16:41:24 -0500690 for (auto locationIt = programOutputVars->begin(); locationIt != programOutputVars->end(); locationIt++)
691 {
692 const VariableLocation &outputLocation = locationIt->second;
Jamie Madill834e8b72014-04-11 13:33:58 -0400693 const ShaderVariable &outputVariable = shaderOutputVars[outputLocation.index];
Jamie Madill5f562732014-02-14 16:41:24 -0500694 const std::string &elementString = (outputLocation.element == GL_INVALID_INDEX ? "" : Str(outputLocation.element));
695
Jamie Madill8664b062014-02-14 16:41:29 -0500696 pixelHLSL += " " + gl_d3d::HLSLTypeString(outputVariable.type) +
Jamie Madill5f562732014-02-14 16:41:24 -0500697 " out_" + outputLocation.name + elementString +
698 " : " + targetSemantic + Str(locationIt->first) + ";\n";
699 }
700 }
701
702 pixelHLSL += "};\n"
703 "\n";
704
705 if (fragmentShader->mUsesFrontFacing)
706 {
707 if (shaderModel >= 4)
708 {
709 pixelHLSL += "PS_OUTPUT main(PS_INPUT input, bool isFrontFace : SV_IsFrontFace)\n"
710 "{\n";
711 }
712 else
713 {
714 pixelHLSL += "PS_OUTPUT main(PS_INPUT input, float vFace : VFACE)\n"
715 "{\n";
716 }
717 }
718 else
719 {
720 pixelHLSL += "PS_OUTPUT main(PS_INPUT input)\n"
721 "{\n";
722 }
723
724 if (fragmentShader->mUsesFragCoord)
725 {
726 pixelHLSL += " float rhw = 1.0 / input.gl_FragCoord.w;\n";
727
728 if (shaderModel >= 4)
729 {
730 pixelHLSL += " gl_FragCoord.x = input.dx_VPos.x;\n"
731 " gl_FragCoord.y = input.dx_VPos.y;\n";
732 }
733 else if (shaderModel >= 3)
734 {
735 pixelHLSL += " gl_FragCoord.x = input.dx_VPos.x + 0.5;\n"
736 " gl_FragCoord.y = input.dx_VPos.y + 0.5;\n";
737 }
738 else
739 {
740 // dx_ViewCoords contains the viewport width/2, height/2, center.x and center.y. See Renderer::setViewport()
741 pixelHLSL += " gl_FragCoord.x = (input.gl_FragCoord.x * rhw) * dx_ViewCoords.x + dx_ViewCoords.z;\n"
742 " gl_FragCoord.y = (input.gl_FragCoord.y * rhw) * dx_ViewCoords.y + dx_ViewCoords.w;\n";
743 }
744
745 pixelHLSL += " gl_FragCoord.z = (input.gl_FragCoord.z * rhw) * dx_DepthFront.x + dx_DepthFront.y;\n"
746 " gl_FragCoord.w = rhw;\n";
747 }
748
749 if (fragmentShader->mUsesPointCoord && shaderModel >= 3)
750 {
751 pixelHLSL += " gl_PointCoord.x = input.gl_PointCoord.x;\n";
752 pixelHLSL += " gl_PointCoord.y = 1.0 - input.gl_PointCoord.y;\n";
753 }
754
755 if (fragmentShader->mUsesFrontFacing)
756 {
757 if (shaderModel <= 3)
758 {
759 pixelHLSL += " gl_FrontFacing = (vFace * dx_DepthFront.z >= 0.0);\n";
760 }
761 else
762 {
763 pixelHLSL += " gl_FrontFacing = isFrontFace;\n";
764 }
765 }
766
767 for (unsigned int varyingIndex = 0; varyingIndex < fragmentShader->mVaryings.size(); varyingIndex++)
768 {
Jamie Madill834e8b72014-04-11 13:33:58 -0400769 Varying *varying = &fragmentShader->mVaryings[varyingIndex];
Jamie Madill5f562732014-02-14 16:41:24 -0500770 if (varying->registerAssigned())
771 {
772 for (unsigned int elementIndex = 0; elementIndex < varying->elementCount(); elementIndex++)
773 {
774 GLenum transposedType = TransposeMatrixType(varying->type);
775 int variableRows = (varying->isStruct() ? 1 : VariableRowCount(transposedType));
776 for (int row = 0; row < variableRows; row++)
777 {
778 std::string n = Str(varying->registerIndex + elementIndex * variableRows + row);
779 pixelHLSL += " _" + varying->name;
780
781 if (varying->isArray())
782 {
783 pixelHLSL += ArrayString(elementIndex);
784 }
785
786 if (variableRows > 1)
787 {
788 pixelHLSL += ArrayString(row);
789 }
790
791 if (varying->isStruct())
792 {
793 pixelHLSL += " = input.v" + n + ";\n"; break;
794 }
795 else
796 {
797 switch (VariableColumnCount(transposedType))
798 {
799 case 1: pixelHLSL += " = input.v" + n + ".x;\n"; break;
800 case 2: pixelHLSL += " = input.v" + n + ".xy;\n"; break;
801 case 3: pixelHLSL += " = input.v" + n + ".xyz;\n"; break;
802 case 4: pixelHLSL += " = input.v" + n + ";\n"; break;
803 default: UNREACHABLE();
804 }
805 }
806 }
807 }
808 }
809 else UNREACHABLE();
810 }
811
812 pixelHLSL += "\n"
813 " gl_main();\n"
814 "\n"
815 " PS_OUTPUT output;\n";
816
817 if (shaderVersion < 300)
818 {
819 for (unsigned int renderTargetIndex = 0; renderTargetIndex < numRenderTargets; renderTargetIndex++)
820 {
821 unsigned int sourceColorIndex = broadcast ? 0 : renderTargetIndex;
822
823 pixelHLSL += " output.gl_Color" + Str(renderTargetIndex) + " = gl_Color[" + Str(sourceColorIndex) + "];\n";
824 }
825
826 if (fragmentShader->mUsesFragDepth)
827 {
828 pixelHLSL += " output.gl_Depth = gl_Depth;\n";
829 }
830 }
831 else
832 {
833 for (auto locationIt = programOutputVars->begin(); locationIt != programOutputVars->end(); locationIt++)
834 {
835 const VariableLocation &outputLocation = locationIt->second;
836 const std::string &variableName = "out_" + outputLocation.name;
837 const std::string &outVariableName = variableName + (outputLocation.element == GL_INVALID_INDEX ? "" : Str(outputLocation.element));
838 const std::string &staticVariableName = variableName + ArrayString(outputLocation.element);
839
840 pixelHLSL += " output." + outVariableName + " = " + staticVariableName + ";\n";
841 }
842 }
843
844 pixelHLSL += "\n"
845 " return output;\n"
846 "}\n";
847
848 return true;
849}
850
851void DynamicHLSL::defineOutputVariables(FragmentShader *fragmentShader, std::map<int, VariableLocation> *programOutputVars) const
852{
Jamie Madill834e8b72014-04-11 13:33:58 -0400853 const std::vector<Attribute> &shaderOutputVars = fragmentShader->getOutputVariables();
Jamie Madill5f562732014-02-14 16:41:24 -0500854
855 for (unsigned int outputVariableIndex = 0; outputVariableIndex < shaderOutputVars.size(); outputVariableIndex++)
856 {
Jamie Madill834e8b72014-04-11 13:33:58 -0400857 const Attribute &outputVariable = shaderOutputVars[outputVariableIndex];
Jamie Madill5f562732014-02-14 16:41:24 -0500858 const int baseLocation = outputVariable.location == -1 ? 0 : outputVariable.location;
859
860 if (outputVariable.arraySize > 0)
861 {
862 for (unsigned int elementIndex = 0; elementIndex < outputVariable.arraySize; elementIndex++)
863 {
864 const int location = baseLocation + elementIndex;
865 ASSERT(programOutputVars->count(location) == 0);
866 (*programOutputVars)[location] = VariableLocation(outputVariable.name, elementIndex, outputVariableIndex);
867 }
868 }
869 else
870 {
871 ASSERT(programOutputVars->count(baseLocation) == 0);
872 (*programOutputVars)[baseLocation] = VariableLocation(outputVariable.name, GL_INVALID_INDEX, outputVariableIndex);
873 }
874 }
875}
876
Jamie Madill834e8b72014-04-11 13:33:58 -0400877std::string DynamicHLSL::generateGeometryShaderHLSL(int registers, const ShaderVariable *packing[][4], FragmentShader *fragmentShader, VertexShader *vertexShader) const
Jamie Madill5f562732014-02-14 16:41:24 -0500878{
879 // for now we only handle point sprite emulation
880 ASSERT(vertexShader->mUsesPointSize && mRenderer->getMajorShaderModel() >= 4);
881 return generatePointSpriteHLSL(registers, packing, fragmentShader, vertexShader);
882}
883
Jamie Madill834e8b72014-04-11 13:33:58 -0400884std::string DynamicHLSL::generatePointSpriteHLSL(int registers, const ShaderVariable *packing[][4], FragmentShader *fragmentShader, VertexShader *vertexShader) const
Jamie Madill5f562732014-02-14 16:41:24 -0500885{
886 ASSERT(registers >= 0);
887 ASSERT(vertexShader->mUsesPointSize);
888 ASSERT(mRenderer->getMajorShaderModel() >= 4);
889
890 std::string geomHLSL;
891
892 std::string varyingSemantic = "TEXCOORD";
893
894 std::string fragCoordSemantic;
895 std::string pointCoordSemantic;
896
897 int reservedRegisterIndex = registers;
898
899 if (fragmentShader->mUsesFragCoord)
900 {
901 fragCoordSemantic = varyingSemantic + Str(reservedRegisterIndex++);
902 }
903
904 if (fragmentShader->mUsesPointCoord)
905 {
906 pointCoordSemantic = varyingSemantic + Str(reservedRegisterIndex++);
907 }
908
909 geomHLSL += "uniform float4 dx_ViewCoords : register(c1);\n"
910 "\n"
911 "struct GS_INPUT\n"
912 "{\n";
913
Geoff Lang48dcae72014-02-05 16:28:24 -0500914 std::string varyingHLSL = generateVaryingHLSL(vertexShader, varyingSemantic, NULL);
Jamie Madill5f562732014-02-14 16:41:24 -0500915
916 geomHLSL += varyingHLSL;
917
918 if (fragmentShader->mUsesFragCoord)
919 {
920 geomHLSL += " float4 gl_FragCoord : " + fragCoordSemantic + ";\n";
921 }
922
923 geomHLSL += " float gl_PointSize : PSIZE;\n"
924 " float4 gl_Position : SV_Position;\n"
925 "};\n"
926 "\n"
927 "struct GS_OUTPUT\n"
928 "{\n";
929
930 geomHLSL += varyingHLSL;
931
932 if (fragmentShader->mUsesFragCoord)
933 {
934 geomHLSL += " float4 gl_FragCoord : " + fragCoordSemantic + ";\n";
935 }
936
937 if (fragmentShader->mUsesPointCoord)
938 {
939 geomHLSL += " float2 gl_PointCoord : " + pointCoordSemantic + ";\n";
940 }
941
942 geomHLSL += " float gl_PointSize : PSIZE;\n"
943 " float4 gl_Position : SV_Position;\n"
944 "};\n"
945 "\n"
946 "static float2 pointSpriteCorners[] = \n"
947 "{\n"
948 " float2( 0.5f, -0.5f),\n"
949 " float2( 0.5f, 0.5f),\n"
950 " float2(-0.5f, -0.5f),\n"
951 " float2(-0.5f, 0.5f)\n"
952 "};\n"
953 "\n"
954 "static float2 pointSpriteTexcoords[] = \n"
955 "{\n"
956 " float2(1.0f, 1.0f),\n"
957 " float2(1.0f, 0.0f),\n"
958 " float2(0.0f, 1.0f),\n"
959 " float2(0.0f, 0.0f)\n"
960 "};\n"
961 "\n"
962 "static float minPointSize = " + Str(ALIASED_POINT_SIZE_RANGE_MIN) + ".0f;\n"
963 "static float maxPointSize = " + Str(mRenderer->getMaxPointSize()) + ".0f;\n"
964 "\n"
965 "[maxvertexcount(4)]\n"
966 "void main(point GS_INPUT input[1], inout TriangleStream<GS_OUTPUT> outStream)\n"
967 "{\n"
968 " GS_OUTPUT output = (GS_OUTPUT)0;\n"
969 " output.gl_PointSize = input[0].gl_PointSize;\n";
970
971 for (int r = 0; r < registers; r++)
972 {
973 geomHLSL += " output.v" + Str(r) + " = input[0].v" + Str(r) + ";\n";
974 }
975
976 if (fragmentShader->mUsesFragCoord)
977 {
978 geomHLSL += " output.gl_FragCoord = input[0].gl_FragCoord;\n";
979 }
980
981 geomHLSL += " \n"
982 " float gl_PointSize = clamp(input[0].gl_PointSize, minPointSize, maxPointSize);\n"
983 " float4 gl_Position = input[0].gl_Position;\n"
984 " float2 viewportScale = float2(1.0f / dx_ViewCoords.x, 1.0f / dx_ViewCoords.y) * gl_Position.w;\n";
985
986 for (int corner = 0; corner < 4; corner++)
987 {
988 geomHLSL += " \n"
989 " output.gl_Position = gl_Position + float4(pointSpriteCorners[" + Str(corner) + "] * viewportScale * gl_PointSize, 0.0f, 0.0f);\n";
990
991 if (fragmentShader->mUsesPointCoord)
992 {
993 geomHLSL += " output.gl_PointCoord = pointSpriteTexcoords[" + Str(corner) + "];\n";
994 }
995
996 geomHLSL += " outStream.Append(output);\n";
997 }
998
999 geomHLSL += " \n"
1000 " outStream.RestartStrip();\n"
1001 "}\n";
1002
1003 return geomHLSL;
1004}
1005
1006// This method needs to match OutputHLSL::decorate
Jamie Madilla53ab512014-03-17 09:47:44 -04001007std::string DynamicHLSL::decorateVariable(const std::string &name)
Jamie Madill5f562732014-02-14 16:41:24 -05001008{
1009 if (name.compare(0, 3, "gl_") != 0 && name.compare(0, 3, "dx_") != 0)
1010 {
1011 return "_" + name;
1012 }
1013
1014 return name;
1015}
1016
Jamie Madill834e8b72014-04-11 13:33:58 -04001017std::string DynamicHLSL::generateAttributeConversionHLSL(const VertexFormat &vertexFormat, const ShaderVariable &shaderAttrib) const
Jamie Madillc5ede1a2014-02-14 16:41:27 -05001018{
Jamie Madilla53ab512014-03-17 09:47:44 -04001019 std::string attribString = "input." + decorateVariable(shaderAttrib.name);
Jamie Madill8664b062014-02-14 16:41:29 -05001020
Jamie Madillc5ede1a2014-02-14 16:41:27 -05001021 // Matrix
1022 if (IsMatrixType(shaderAttrib.type))
1023 {
Jamie Madill8664b062014-02-14 16:41:29 -05001024 return "transpose(" + attribString + ")";
Jamie Madillc5ede1a2014-02-14 16:41:27 -05001025 }
1026
Jamie Madill8664b062014-02-14 16:41:29 -05001027 GLenum shaderComponentType = UniformComponentType(shaderAttrib.type);
1028 int shaderComponentCount = UniformComponentCount(shaderAttrib.type);
1029
1030 std::string padString = "";
1031
1032 // Perform integer to float conversion (if necessary)
1033 bool requiresTypeConversion = (shaderComponentType == GL_FLOAT && vertexFormat.mType != GL_FLOAT);
1034
1035 // TODO: normalization for 32-bit integer formats
1036 ASSERT(!requiresTypeConversion || !vertexFormat.mNormalized);
1037
1038 if (requiresTypeConversion || !padString.empty())
1039 {
1040 return "float" + Str(shaderComponentCount) + "(" + attribString + padString + ")";
1041 }
Jamie Madillc5ede1a2014-02-14 16:41:27 -05001042
1043 // No conversion necessary
Jamie Madill8664b062014-02-14 16:41:29 -05001044 return attribString;
Jamie Madillc5ede1a2014-02-14 16:41:27 -05001045}
1046
Jamie Madill5f562732014-02-14 16:41:24 -05001047}