Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1 | // |
| 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 Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 9 | #include "libANGLE/renderer/d3d/DynamicHLSL.h" |
Jamie Madill | 9e0478f | 2015-01-13 11:13:54 -0500 | [diff] [blame] | 10 | |
| 11 | #include "common/utilities.h" |
Daniel Bratell | 73941de | 2015-02-25 14:34:49 +0100 | [diff] [blame] | 12 | #include "compiler/translator/blocklayoutHLSL.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 13 | #include "libANGLE/renderer/d3d/ShaderD3D.h" |
| 14 | #include "libANGLE/renderer/d3d/RendererD3D.h" |
| 15 | #include "libANGLE/Program.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 16 | #include "libANGLE/Shader.h" |
| 17 | #include "libANGLE/formatutils.h" |
Geoff Lang | 0b7eef7 | 2014-06-12 14:10:47 -0400 | [diff] [blame] | 18 | |
Jamie Madill | 53cb14d | 2014-07-08 15:02:35 -0400 | [diff] [blame] | 19 | // For use with ArrayString, see angleutils.h |
| 20 | META_ASSERT(GL_INVALID_INDEX == UINT_MAX); |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 21 | |
Brandon Jones | d8d7243 | 2014-08-22 15:11:23 -0700 | [diff] [blame] | 22 | using namespace gl; |
| 23 | |
Jamie Madill | 30d6c25 | 2014-11-13 10:03:33 -0500 | [diff] [blame] | 24 | namespace rx |
| 25 | { |
| 26 | |
Jamie Madill | 3f2e61d | 2014-09-05 10:38:05 -0400 | [diff] [blame] | 27 | namespace |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 28 | { |
Jamie Madill | 8664b06 | 2014-02-14 16:41:29 -0500 | [diff] [blame] | 29 | |
| 30 | std::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 Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 41 | } |
| 42 | |
Jamie Madill | 8664b06 | 2014-02-14 16:41:29 -0500 | [diff] [blame] | 43 | std::string HLSLComponentTypeString(GLenum componentType, int componentCount) |
| 44 | { |
| 45 | return HLSLComponentTypeString(componentType) + (componentCount > 1 ? Str(componentCount) : ""); |
| 46 | } |
| 47 | |
| 48 | std::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 | |
| 65 | std::string HLSLTypeString(GLenum type) |
| 66 | { |
| 67 | if (gl::IsMatrixType(type)) |
| 68 | { |
| 69 | return HLSLMatrixTypeString(type); |
| 70 | } |
| 71 | |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 72 | return HLSLComponentTypeString(gl::VariableComponentType(type), gl::VariableComponentCount(type)); |
Jamie Madill | 8664b06 | 2014-02-14 16:41:29 -0500 | [diff] [blame] | 73 | } |
| 74 | |
Gregoire Payen de La Garanderie | e172854 | 2015-01-07 11:31:54 +0000 | [diff] [blame] | 75 | const PixelShaderOutputVariable *FindOutputAtLocation(const std::vector<PixelShaderOutputVariable> &outputVariables, |
Jamie Madill | 3f2e61d | 2014-09-05 10:38:05 -0400 | [diff] [blame] | 76 | 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 Garanderie | e172854 | 2015-01-07 11:31:54 +0000 | [diff] [blame] | 82 | return &outputVariables[variableIndex]; |
Jamie Madill | 3f2e61d | 2014-09-05 10:38:05 -0400 | [diff] [blame] | 83 | } |
| 84 | } |
| 85 | |
Gregoire Payen de La Garanderie | e172854 | 2015-01-07 11:31:54 +0000 | [diff] [blame] | 86 | return NULL; |
Jamie Madill | 3f2e61d | 2014-09-05 10:38:05 -0400 | [diff] [blame] | 87 | } |
| 88 | |
Geoff Lang | 04fb89a | 2014-06-09 15:05:36 -0400 | [diff] [blame] | 89 | const std::string VERTEX_ATTRIBUTE_STUB_STRING = "@@ VERTEX ATTRIBUTES @@"; |
| 90 | const std::string PIXEL_OUTPUT_STUB_STRING = "@@ PIXEL OUTPUT @@"; |
Jamie Madill | c5ede1a | 2014-02-14 16:41:27 -0500 | [diff] [blame] | 91 | |
Jamie Madill | 30d6c25 | 2014-11-13 10:03:33 -0500 | [diff] [blame] | 92 | } |
| 93 | |
Jamie Madill | 93e13fb | 2014-11-06 15:27:25 -0500 | [diff] [blame] | 94 | DynamicHLSL::DynamicHLSL(RendererD3D *const renderer) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 95 | : mRenderer(renderer) |
| 96 | { |
| 97 | } |
| 98 | |
Jamie Madill | ff0d2ba | 2014-05-14 13:49:10 -0400 | [diff] [blame] | 99 | static bool packVarying(PackedVarying *varying, const int maxVaryingVectors, VaryingPacking packing) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 100 | { |
Jamie Madill | f4780c1 | 2015-02-11 16:33:11 -0500 | [diff] [blame] | 101 | // Make sure we use transposed matrix types to count registers correctly. |
| 102 | int registers = 0; |
| 103 | int elements = 0; |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 104 | |
Jamie Madill | f4780c1 | 2015-02-11 16:33:11 -0500 | [diff] [blame] | 105 | if (varying->isStruct()) |
| 106 | { |
| 107 | registers = HLSLVariableRegisterCount(*varying, true) * varying->elementCount(); |
| 108 | elements = 4; |
| 109 | } |
| 110 | else |
| 111 | { |
| 112 | GLenum transposedType = TransposeMatrixType(varying->type); |
| 113 | registers = VariableRowCount(transposedType) * varying->elementCount(); |
| 114 | elements = VariableColumnCount(transposedType); |
| 115 | } |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 116 | |
Jamie Madill | ff0d2ba | 2014-05-14 13:49:10 -0400 | [diff] [blame] | 117 | if (elements >= 2 && elements <= 4) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 118 | { |
Jamie Madill | ff0d2ba | 2014-05-14 13:49:10 -0400 | [diff] [blame] | 119 | for (int r = 0; r <= maxVaryingVectors - registers; r++) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 120 | { |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 121 | bool available = true; |
| 122 | |
| 123 | for (int y = 0; y < registers && available; y++) |
| 124 | { |
| 125 | for (int x = 0; x < elements && available; x++) |
| 126 | { |
| 127 | if (packing[r + y][x]) |
| 128 | { |
| 129 | available = false; |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | if (available) |
| 135 | { |
| 136 | varying->registerIndex = r; |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 137 | varying->columnIndex = 0; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 138 | |
| 139 | for (int y = 0; y < registers; y++) |
| 140 | { |
| 141 | for (int x = 0; x < elements; x++) |
| 142 | { |
| 143 | packing[r + y][x] = &*varying; |
| 144 | } |
| 145 | } |
| 146 | |
Jamie Madill | ff0d2ba | 2014-05-14 13:49:10 -0400 | [diff] [blame] | 147 | return true; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | |
Jamie Madill | ff0d2ba | 2014-05-14 13:49:10 -0400 | [diff] [blame] | 151 | if (elements == 2) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 152 | { |
Jamie Madill | ff0d2ba | 2014-05-14 13:49:10 -0400 | [diff] [blame] | 153 | for (int r = maxVaryingVectors - registers; r >= 0; r--) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 154 | { |
| 155 | bool available = true; |
| 156 | |
| 157 | for (int y = 0; y < registers && available; y++) |
| 158 | { |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 159 | for (int x = 2; x < 4 && available; x++) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 160 | { |
| 161 | if (packing[r + y][x]) |
| 162 | { |
| 163 | available = false; |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | if (available) |
| 169 | { |
| 170 | varying->registerIndex = r; |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 171 | varying->columnIndex = 2; |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 172 | |
| 173 | for (int y = 0; y < registers; y++) |
| 174 | { |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 175 | for (int x = 2; x < 4; x++) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 176 | { |
| 177 | packing[r + y][x] = &*varying; |
| 178 | } |
| 179 | } |
| 180 | |
Jamie Madill | ff0d2ba | 2014-05-14 13:49:10 -0400 | [diff] [blame] | 181 | return true; |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 182 | } |
| 183 | } |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 184 | } |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 185 | } |
| 186 | else if (elements == 1) |
| 187 | { |
| 188 | int space[4] = { 0 }; |
| 189 | |
| 190 | for (int y = 0; y < maxVaryingVectors; y++) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 191 | { |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 192 | for (int x = 0; x < 4; x++) |
| 193 | { |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 194 | space[x] += packing[y][x] ? 0 : 1; |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 195 | } |
| 196 | } |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 197 | |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 198 | int column = 0; |
| 199 | |
| 200 | for (int x = 0; x < 4; x++) |
| 201 | { |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 202 | if (space[x] >= registers && (space[column] < registers || space[x] < space[column])) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 203 | { |
| 204 | column = x; |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | if (space[column] >= registers) |
| 209 | { |
| 210 | for (int r = 0; r < maxVaryingVectors; r++) |
| 211 | { |
| 212 | if (!packing[r][column]) |
| 213 | { |
| 214 | varying->registerIndex = r; |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 215 | varying->columnIndex = column; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 216 | |
| 217 | for (int y = r; y < r + registers; y++) |
| 218 | { |
| 219 | packing[y][column] = &*varying; |
| 220 | } |
| 221 | |
| 222 | break; |
| 223 | } |
| 224 | } |
| 225 | |
Jamie Madill | ff0d2ba | 2014-05-14 13:49:10 -0400 | [diff] [blame] | 226 | return true; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | else UNREACHABLE(); |
| 230 | |
Jamie Madill | ff0d2ba | 2014-05-14 13:49:10 -0400 | [diff] [blame] | 231 | return false; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | // Packs varyings into generic varying registers, using the algorithm from [OpenGL ES Shading Language 1.00 rev. 17] appendix A section 7 page 111 |
| 235 | // Returns the number of used varying registers, or -1 if unsuccesful |
Jamie Madill | 30d6c25 | 2014-11-13 10:03:33 -0500 | [diff] [blame] | 236 | int DynamicHLSL::packVaryings(InfoLog &infoLog, VaryingPacking packing, ShaderD3D *fragmentShader, |
| 237 | ShaderD3D *vertexShader, const std::vector<std::string> &transformFeedbackVaryings) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 238 | { |
Geoff Lang | 3a61c32 | 2014-07-10 13:01:54 -0400 | [diff] [blame] | 239 | // TODO (geofflang): Use context's caps |
| 240 | const int maxVaryingVectors = mRenderer->getRendererCaps().maxVaryingVectors; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 241 | |
Brandon Jones | 7162096 | 2014-08-20 14:04:59 -0700 | [diff] [blame] | 242 | vertexShader->resetVaryingsRegisterAssignment(); |
| 243 | fragmentShader->resetVaryingsRegisterAssignment(); |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 244 | |
| 245 | std::set<std::string> packedVaryings; |
| 246 | |
Jamie Madill | d15250e | 2014-09-03 09:40:44 -0400 | [diff] [blame] | 247 | std::vector<gl::PackedVarying> &fragmentVaryings = fragmentShader->getVaryings(); |
| 248 | std::vector<gl::PackedVarying> &vertexVaryings = vertexShader->getVaryings(); |
| 249 | for (unsigned int varyingIndex = 0; varyingIndex < fragmentVaryings.size(); varyingIndex++) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 250 | { |
Jamie Madill | d15250e | 2014-09-03 09:40:44 -0400 | [diff] [blame] | 251 | PackedVarying *varying = &fragmentVaryings[varyingIndex]; |
Jamie Madill | 54ad4f8 | 2014-09-03 09:40:46 -0400 | [diff] [blame] | 252 | |
| 253 | // Do not assign registers to built-in or unreferenced varyings |
| 254 | if (varying->isBuiltIn() || !varying->staticUse) |
| 255 | { |
| 256 | continue; |
| 257 | } |
| 258 | |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 259 | if (packVarying(varying, maxVaryingVectors, packing)) |
| 260 | { |
| 261 | packedVaryings.insert(varying->name); |
| 262 | } |
| 263 | else |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 264 | { |
| 265 | infoLog.append("Could not pack varying %s", varying->name.c_str()); |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 266 | return -1; |
| 267 | } |
| 268 | } |
| 269 | |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 270 | for (unsigned int feedbackVaryingIndex = 0; feedbackVaryingIndex < transformFeedbackVaryings.size(); feedbackVaryingIndex++) |
| 271 | { |
| 272 | const std::string &transformFeedbackVarying = transformFeedbackVaryings[feedbackVaryingIndex]; |
Jamie Madill | 55d611e | 2014-10-24 16:28:14 -0400 | [diff] [blame] | 273 | |
| 274 | if (transformFeedbackVarying == "gl_Position" || transformFeedbackVarying == "gl_PointSize") |
| 275 | { |
| 276 | // do not pack builtin XFB varyings |
| 277 | continue; |
| 278 | } |
| 279 | |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 280 | if (packedVaryings.find(transformFeedbackVarying) == packedVaryings.end()) |
| 281 | { |
| 282 | bool found = false; |
Jamie Madill | d15250e | 2014-09-03 09:40:44 -0400 | [diff] [blame] | 283 | for (unsigned int varyingIndex = 0; varyingIndex < vertexVaryings.size(); varyingIndex++) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 284 | { |
Jamie Madill | d15250e | 2014-09-03 09:40:44 -0400 | [diff] [blame] | 285 | PackedVarying *varying = &vertexVaryings[varyingIndex]; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 286 | if (transformFeedbackVarying == varying->name) |
| 287 | { |
| 288 | if (!packVarying(varying, maxVaryingVectors, packing)) |
| 289 | { |
| 290 | infoLog.append("Could not pack varying %s", varying->name.c_str()); |
| 291 | return -1; |
| 292 | } |
| 293 | |
| 294 | found = true; |
| 295 | break; |
| 296 | } |
| 297 | } |
| 298 | |
Jamie Madill | 55d611e | 2014-10-24 16:28:14 -0400 | [diff] [blame] | 299 | if (!found) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 300 | { |
| 301 | infoLog.append("Transform feedback varying %s does not exist in the vertex shader.", transformFeedbackVarying.c_str()); |
| 302 | return -1; |
| 303 | } |
| 304 | } |
| 305 | } |
| 306 | |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 307 | // Return the number of used registers |
| 308 | int registers = 0; |
| 309 | |
| 310 | for (int r = 0; r < maxVaryingVectors; r++) |
| 311 | { |
| 312 | if (packing[r][0] || packing[r][1] || packing[r][2] || packing[r][3]) |
| 313 | { |
| 314 | registers++; |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | return registers; |
| 319 | } |
| 320 | |
Jamie Madill | 54ad4f8 | 2014-09-03 09:40:46 -0400 | [diff] [blame] | 321 | std::string DynamicHLSL::generateVaryingHLSL(const ShaderD3D *shader) const |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 322 | { |
Brandon Jones | 7162096 | 2014-08-20 14:04:59 -0700 | [diff] [blame] | 323 | std::string varyingSemantic = getVaryingSemantic(shader->mUsesPointSize); |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 324 | std::string varyingHLSL; |
| 325 | |
Jamie Madill | 54ad4f8 | 2014-09-03 09:40:46 -0400 | [diff] [blame] | 326 | const std::vector<gl::PackedVarying> &varyings = shader->getVaryings(); |
| 327 | |
Jamie Madill | d15250e | 2014-09-03 09:40:44 -0400 | [diff] [blame] | 328 | for (unsigned int varyingIndex = 0; varyingIndex < varyings.size(); varyingIndex++) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 329 | { |
Jamie Madill | d15250e | 2014-09-03 09:40:44 -0400 | [diff] [blame] | 330 | const PackedVarying &varying = varyings[varyingIndex]; |
Jamie Madill | ff0d2ba | 2014-05-14 13:49:10 -0400 | [diff] [blame] | 331 | if (varying.registerAssigned()) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 332 | { |
Jamie Madill | 54ad4f8 | 2014-09-03 09:40:46 -0400 | [diff] [blame] | 333 | ASSERT(!varying.isBuiltIn()); |
Jamie Madill | ff0d2ba | 2014-05-14 13:49:10 -0400 | [diff] [blame] | 334 | GLenum transposedType = TransposeMatrixType(varying.type); |
| 335 | int variableRows = (varying.isStruct() ? 1 : VariableRowCount(transposedType)); |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 336 | |
Jamie Madill | ff0d2ba | 2014-05-14 13:49:10 -0400 | [diff] [blame] | 337 | for (unsigned int elementIndex = 0; elementIndex < varying.elementCount(); elementIndex++) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 338 | { |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 339 | for (int row = 0; row < variableRows; row++) |
| 340 | { |
Austin Kinross | af87552 | 2014-08-25 21:06:07 -0700 | [diff] [blame] | 341 | // TODO: Add checks to ensure D3D interpolation modifiers don't result in too many registers being used. |
| 342 | // For example, if there are N registers, and we have N vec3 varyings and 1 float varying, then D3D will pack them into N registers. |
| 343 | // If the float varying has the 'nointerpolation' modifier on it then we would need N + 1 registers, and D3D compilation will fail. |
| 344 | |
Jamie Madill | ff0d2ba | 2014-05-14 13:49:10 -0400 | [diff] [blame] | 345 | switch (varying.interpolation) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 346 | { |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 347 | case sh::INTERPOLATION_SMOOTH: varyingHLSL += " "; break; |
| 348 | case sh::INTERPOLATION_FLAT: varyingHLSL += " nointerpolation "; break; |
| 349 | case sh::INTERPOLATION_CENTROID: varyingHLSL += " centroid "; break; |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 350 | default: UNREACHABLE(); |
| 351 | } |
| 352 | |
Jamie Madill | f4780c1 | 2015-02-11 16:33:11 -0500 | [diff] [blame] | 353 | unsigned int semanticIndex = elementIndex * variableRows + |
| 354 | varying.columnIndex * mRenderer->getRendererCaps().maxVaryingVectors + |
| 355 | varying.registerIndex + row; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 356 | std::string n = Str(semanticIndex); |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 357 | |
Jamie Madill | a53ab51 | 2014-03-17 09:47:44 -0400 | [diff] [blame] | 358 | std::string typeString; |
| 359 | |
Jamie Madill | ff0d2ba | 2014-05-14 13:49:10 -0400 | [diff] [blame] | 360 | if (varying.isStruct()) |
Jamie Madill | a53ab51 | 2014-03-17 09:47:44 -0400 | [diff] [blame] | 361 | { |
Jamie Madill | f4780c1 | 2015-02-11 16:33:11 -0500 | [diff] [blame] | 362 | // TODO(jmadill): pass back translated name from the shader translator |
Jamie Madill | ff0d2ba | 2014-05-14 13:49:10 -0400 | [diff] [blame] | 363 | typeString = decorateVariable(varying.structName); |
Jamie Madill | a53ab51 | 2014-03-17 09:47:44 -0400 | [diff] [blame] | 364 | } |
| 365 | else |
| 366 | { |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 367 | GLenum componentType = VariableComponentType(transposedType); |
Jamie Madill | 834e8b7 | 2014-04-11 13:33:58 -0400 | [diff] [blame] | 368 | int columnCount = VariableColumnCount(transposedType); |
Jamie Madill | 3f2e61d | 2014-09-05 10:38:05 -0400 | [diff] [blame] | 369 | typeString = HLSLComponentTypeString(componentType, columnCount); |
Jamie Madill | a53ab51 | 2014-03-17 09:47:44 -0400 | [diff] [blame] | 370 | } |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 371 | varyingHLSL += typeString + " v" + n + " : " + varyingSemantic + n + ";\n"; |
| 372 | } |
| 373 | } |
| 374 | } |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | return varyingHLSL; |
| 378 | } |
| 379 | |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 380 | std::string DynamicHLSL::generateVertexShaderForInputLayout(const std::string &sourceShader, |
| 381 | const VertexFormat inputLayout[], |
| 382 | const sh::Attribute shaderAttributes[]) const |
Jamie Madill | c5ede1a | 2014-02-14 16:41:27 -0500 | [diff] [blame] | 383 | { |
Jamie Madill | 3b7e205 | 2014-03-17 09:47:43 -0400 | [diff] [blame] | 384 | std::string structHLSL, initHLSL; |
Jamie Madill | c5ede1a | 2014-02-14 16:41:27 -0500 | [diff] [blame] | 385 | |
| 386 | int semanticIndex = 0; |
Jamie Madill | 3b7e205 | 2014-03-17 09:47:43 -0400 | [diff] [blame] | 387 | unsigned int inputIndex = 0; |
| 388 | |
Cooper Partin | e6d14cc | 2015-02-20 12:32:58 -0800 | [diff] [blame] | 389 | // If gl_PointSize is used in the shader then pointsprites rendering is expected. |
| 390 | // If the renderer does not support Geometry shaders then Instanced PointSprite emulation |
| 391 | // must be used. |
| 392 | bool usesPointSize = sourceShader.find("GL_USES_POINT_SIZE") != std::string::npos; |
| 393 | bool useInstancedPointSpriteEmulation = usesPointSize && mRenderer->getWorkarounds().useInstancedPointSpriteEmulation; |
| 394 | |
| 395 | // Instanced PointSprite emulation requires additional entries in the |
| 396 | // VS_INPUT structure to support the vertices that make up the quad vertices. |
| 397 | // These values must be in sync with the cooresponding values added during inputlayout creation |
| 398 | // in InputLayoutCache::applyVertexBuffers(). |
| 399 | // |
| 400 | // The additional entries must appear first in the VS_INPUT layout because |
| 401 | // Windows Phone 8 era devices require per vertex data to physically come |
| 402 | // before per instance data in the shader. |
| 403 | if (useInstancedPointSpriteEmulation) |
| 404 | { |
| 405 | structHLSL += " float3 spriteVertexPos : SPRITEPOSITION0;\n"; |
| 406 | structHLSL += " float2 spriteTexCoord : SPRITETEXCOORD0;\n"; |
| 407 | } |
| 408 | |
Jamie Madill | c5ede1a | 2014-02-14 16:41:27 -0500 | [diff] [blame] | 409 | for (unsigned int attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++) |
| 410 | { |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 411 | const sh::Attribute &shaderAttribute = shaderAttributes[attributeIndex]; |
Jamie Madill | 8664b06 | 2014-02-14 16:41:29 -0500 | [diff] [blame] | 412 | if (!shaderAttribute.name.empty()) |
Jamie Madill | c5ede1a | 2014-02-14 16:41:27 -0500 | [diff] [blame] | 413 | { |
Geoff Lang | 5ac5ae8 | 2014-09-09 10:14:17 -0400 | [diff] [blame] | 414 | ASSERT(inputIndex < MAX_VERTEX_ATTRIBS); |
| 415 | const VertexFormat &vertexFormat = inputLayout[inputIndex]; |
| 416 | |
Jamie Madill | 3b7e205 | 2014-03-17 09:47:43 -0400 | [diff] [blame] | 417 | // HLSL code for input structure |
Jamie Madill | 8664b06 | 2014-02-14 16:41:29 -0500 | [diff] [blame] | 418 | if (IsMatrixType(shaderAttribute.type)) |
| 419 | { |
| 420 | // Matrix types are always transposed |
Jamie Madill | 3f2e61d | 2014-09-05 10:38:05 -0400 | [diff] [blame] | 421 | structHLSL += " " + HLSLMatrixTypeString(TransposeMatrixType(shaderAttribute.type)); |
Jamie Madill | 8664b06 | 2014-02-14 16:41:29 -0500 | [diff] [blame] | 422 | } |
| 423 | else |
| 424 | { |
| 425 | GLenum componentType = mRenderer->getVertexComponentType(vertexFormat); |
Gregoire Payen de La Garanderie | b3dced2 | 2015-01-12 14:54:55 +0000 | [diff] [blame] | 426 | |
| 427 | if (shaderAttribute.name == "gl_InstanceID") |
| 428 | { |
| 429 | // The input type of the instance ID in HLSL (uint) differs from the one in ESSL (int). |
| 430 | structHLSL += " uint"; |
| 431 | } |
| 432 | else |
| 433 | { |
| 434 | structHLSL += " " + HLSLComponentTypeString(componentType, VariableComponentCount(shaderAttribute.type)); |
| 435 | } |
Jamie Madill | 8664b06 | 2014-02-14 16:41:29 -0500 | [diff] [blame] | 436 | } |
Jamie Madill | c5ede1a | 2014-02-14 16:41:27 -0500 | [diff] [blame] | 437 | |
Gregoire Payen de La Garanderie | b3dced2 | 2015-01-12 14:54:55 +0000 | [diff] [blame] | 438 | structHLSL += " " + decorateVariable(shaderAttribute.name) + " : "; |
| 439 | |
| 440 | if (shaderAttribute.name == "gl_InstanceID") |
| 441 | { |
| 442 | structHLSL += "SV_InstanceID"; |
| 443 | } |
| 444 | else |
| 445 | { |
| 446 | structHLSL += "TEXCOORD" + Str(semanticIndex); |
| 447 | semanticIndex += VariableRegisterCount(shaderAttribute.type); |
| 448 | } |
| 449 | |
| 450 | structHLSL += ";\n"; |
Jamie Madill | c5ede1a | 2014-02-14 16:41:27 -0500 | [diff] [blame] | 451 | |
Jamie Madill | 3b7e205 | 2014-03-17 09:47:43 -0400 | [diff] [blame] | 452 | // HLSL code for initialization |
Jamie Madill | a53ab51 | 2014-03-17 09:47:44 -0400 | [diff] [blame] | 453 | initHLSL += " " + decorateVariable(shaderAttribute.name) + " = "; |
Jamie Madill | 8664b06 | 2014-02-14 16:41:29 -0500 | [diff] [blame] | 454 | |
| 455 | // Mismatched vertex attribute to vertex input may result in an undefined |
| 456 | // data reinterpretation (eg for pure integer->float, float->pure integer) |
| 457 | // TODO: issue warning with gl debug info extension, when supported |
Jamie Madill | 3b7e205 | 2014-03-17 09:47:43 -0400 | [diff] [blame] | 458 | if (IsMatrixType(shaderAttribute.type) || |
Jamie Madill | 30d6c25 | 2014-11-13 10:03:33 -0500 | [diff] [blame] | 459 | (mRenderer->getVertexConversionType(vertexFormat) & VERTEX_CONVERT_GPU) != 0) |
Jamie Madill | 8664b06 | 2014-02-14 16:41:29 -0500 | [diff] [blame] | 460 | { |
Jamie Madill | 3b7e205 | 2014-03-17 09:47:43 -0400 | [diff] [blame] | 461 | initHLSL += generateAttributeConversionHLSL(vertexFormat, shaderAttribute); |
Jamie Madill | 8664b06 | 2014-02-14 16:41:29 -0500 | [diff] [blame] | 462 | } |
| 463 | else |
| 464 | { |
Jamie Madill | a53ab51 | 2014-03-17 09:47:44 -0400 | [diff] [blame] | 465 | initHLSL += "input." + decorateVariable(shaderAttribute.name); |
Jamie Madill | 8664b06 | 2014-02-14 16:41:29 -0500 | [diff] [blame] | 466 | } |
| 467 | |
Jamie Madill | 3b7e205 | 2014-03-17 09:47:43 -0400 | [diff] [blame] | 468 | initHLSL += ";\n"; |
Jamie Madill | 3b7e205 | 2014-03-17 09:47:43 -0400 | [diff] [blame] | 469 | |
Jamie Madill | ac0a267 | 2014-04-11 13:33:56 -0400 | [diff] [blame] | 470 | inputIndex += VariableRowCount(TransposeMatrixType(shaderAttribute.type)); |
| 471 | } |
Jamie Madill | c5ede1a | 2014-02-14 16:41:27 -0500 | [diff] [blame] | 472 | } |
| 473 | |
Geoff Lang | 04fb89a | 2014-06-09 15:05:36 -0400 | [diff] [blame] | 474 | std::string replacementHLSL = "struct VS_INPUT\n" |
| 475 | "{\n" + |
| 476 | structHLSL + |
| 477 | "};\n" |
| 478 | "\n" |
| 479 | "void initAttributes(VS_INPUT input)\n" |
| 480 | "{\n" + |
| 481 | initHLSL + |
| 482 | "}\n"; |
| 483 | |
| 484 | std::string vertexHLSL(sourceShader); |
| 485 | |
| 486 | size_t copyInsertionPos = vertexHLSL.find(VERTEX_ATTRIBUTE_STUB_STRING); |
| 487 | vertexHLSL.replace(copyInsertionPos, VERTEX_ATTRIBUTE_STUB_STRING.length(), replacementHLSL); |
| 488 | |
| 489 | return vertexHLSL; |
| 490 | } |
| 491 | |
Jamie Madill | f6be8d7 | 2014-09-05 10:38:07 -0400 | [diff] [blame] | 492 | std::string DynamicHLSL::generatePixelShaderForOutputSignature(const std::string &sourceShader, const std::vector<PixelShaderOutputVariable> &outputVariables, |
Geoff Lang | 04fb89a | 2014-06-09 15:05:36 -0400 | [diff] [blame] | 493 | bool usesFragDepth, const std::vector<GLenum> &outputLayout) const |
| 494 | { |
| 495 | const int shaderModel = mRenderer->getMajorShaderModel(); |
| 496 | std::string targetSemantic = (shaderModel >= 4) ? "SV_TARGET" : "COLOR"; |
| 497 | std::string depthSemantic = (shaderModel >= 4) ? "SV_Depth" : "DEPTH"; |
| 498 | |
| 499 | std::string declarationHLSL; |
| 500 | std::string copyHLSL; |
Geoff Lang | 4ace423 | 2014-06-18 19:12:48 -0400 | [diff] [blame] | 501 | |
Jamie Madill | 3f2e61d | 2014-09-05 10:38:05 -0400 | [diff] [blame] | 502 | for (size_t layoutIndex = 0; layoutIndex < outputLayout.size(); ++layoutIndex) |
| 503 | { |
| 504 | GLenum binding = outputLayout[layoutIndex]; |
| 505 | |
| 506 | if (binding != GL_NONE) |
Geoff Lang | 04fb89a | 2014-06-09 15:05:36 -0400 | [diff] [blame] | 507 | { |
Jamie Madill | 3f2e61d | 2014-09-05 10:38:05 -0400 | [diff] [blame] | 508 | unsigned int location = (binding - GL_COLOR_ATTACHMENT0); |
| 509 | |
Gregoire Payen de La Garanderie | e172854 | 2015-01-07 11:31:54 +0000 | [diff] [blame] | 510 | const PixelShaderOutputVariable *outputVariable = FindOutputAtLocation(outputVariables, location); |
Jamie Madill | 3f2e61d | 2014-09-05 10:38:05 -0400 | [diff] [blame] | 511 | |
Gregoire Payen de La Garanderie | e172854 | 2015-01-07 11:31:54 +0000 | [diff] [blame] | 512 | // OpenGL ES 3.0 spec $4.2.1 |
| 513 | // If [...] not all user-defined output variables are written, the values of fragment colors |
| 514 | // corresponding to unwritten variables are similarly undefined. |
| 515 | if (outputVariable) |
| 516 | { |
| 517 | declarationHLSL += " " + HLSLTypeString(outputVariable->type) + " " + outputVariable->name + |
| 518 | " : " + targetSemantic + Str(layoutIndex) + ";\n"; |
Geoff Lang | 04fb89a | 2014-06-09 15:05:36 -0400 | [diff] [blame] | 519 | |
Gregoire Payen de La Garanderie | e172854 | 2015-01-07 11:31:54 +0000 | [diff] [blame] | 520 | copyHLSL += " output." + outputVariable->name + " = " + outputVariable->source + ";\n"; |
| 521 | } |
Geoff Lang | 04fb89a | 2014-06-09 15:05:36 -0400 | [diff] [blame] | 522 | } |
| 523 | } |
| 524 | |
| 525 | if (usesFragDepth) |
| 526 | { |
| 527 | declarationHLSL += " float gl_Depth : " + depthSemantic + ";\n"; |
| 528 | copyHLSL += " output.gl_Depth = gl_Depth; \n"; |
| 529 | } |
| 530 | |
| 531 | std::string replacementHLSL = "struct PS_OUTPUT\n" |
| 532 | "{\n" + |
| 533 | declarationHLSL + |
| 534 | "};\n" |
| 535 | "\n" |
| 536 | "PS_OUTPUT generateOutput()\n" |
| 537 | "{\n" |
| 538 | " PS_OUTPUT output;\n" + |
| 539 | copyHLSL + |
| 540 | " return output;\n" |
| 541 | "}\n"; |
| 542 | |
| 543 | std::string pixelHLSL(sourceShader); |
| 544 | |
| 545 | size_t outputInsertionPos = pixelHLSL.find(PIXEL_OUTPUT_STUB_STRING); |
| 546 | pixelHLSL.replace(outputInsertionPos, PIXEL_OUTPUT_STUB_STRING.length(), replacementHLSL); |
| 547 | |
| 548 | return pixelHLSL; |
Jamie Madill | c5ede1a | 2014-02-14 16:41:27 -0500 | [diff] [blame] | 549 | } |
| 550 | |
Jamie Madill | febb7ad | 2014-06-18 13:50:51 -0400 | [diff] [blame] | 551 | std::string DynamicHLSL::getVaryingSemantic(bool pointSize) const |
| 552 | { |
| 553 | // SM3 reserves the TEXCOORD semantic for point sprite texcoords (gl_PointCoord) |
| 554 | // In D3D11 we manually compute gl_PointCoord in the GS. |
| 555 | int shaderModel = mRenderer->getMajorShaderModel(); |
| 556 | return ((pointSize && shaderModel < 4) ? "COLOR" : "TEXCOORD"); |
| 557 | } |
| 558 | |
| 559 | struct DynamicHLSL::SemanticInfo |
| 560 | { |
| 561 | struct BuiltinInfo |
| 562 | { |
| 563 | BuiltinInfo() |
| 564 | : enabled(false), |
| 565 | index(0), |
| 566 | systemValue(false) |
| 567 | {} |
| 568 | |
| 569 | bool enabled; |
| 570 | std::string semantic; |
| 571 | unsigned int index; |
| 572 | bool systemValue; |
| 573 | |
| 574 | std::string str() const |
| 575 | { |
| 576 | return (systemValue ? semantic : (semantic + Str(index))); |
| 577 | } |
| 578 | |
| 579 | void enableSystem(const std::string &systemValueSemantic) |
| 580 | { |
| 581 | enabled = true; |
| 582 | semantic = systemValueSemantic; |
| 583 | systemValue = true; |
| 584 | } |
| 585 | |
| 586 | void enable(const std::string &semanticVal, unsigned int indexVal) |
| 587 | { |
| 588 | enabled = true; |
| 589 | semantic = semanticVal; |
| 590 | index = indexVal; |
| 591 | } |
| 592 | }; |
| 593 | |
| 594 | BuiltinInfo dxPosition; |
| 595 | BuiltinInfo glPosition; |
| 596 | BuiltinInfo glFragCoord; |
| 597 | BuiltinInfo glPointCoord; |
| 598 | BuiltinInfo glPointSize; |
| 599 | }; |
| 600 | |
| 601 | DynamicHLSL::SemanticInfo DynamicHLSL::getSemanticInfo(int startRegisters, bool fragCoord, bool pointCoord, |
| 602 | bool pointSize, bool pixelShader) const |
| 603 | { |
| 604 | SemanticInfo info; |
| 605 | bool hlsl4 = (mRenderer->getMajorShaderModel() >= 4); |
| 606 | const std::string &varyingSemantic = getVaryingSemantic(pointSize); |
| 607 | |
| 608 | int reservedRegisterIndex = startRegisters; |
| 609 | |
| 610 | if (hlsl4) |
| 611 | { |
| 612 | info.dxPosition.enableSystem("SV_Position"); |
| 613 | } |
| 614 | else if (pixelShader) |
| 615 | { |
| 616 | info.dxPosition.enableSystem("VPOS"); |
| 617 | } |
| 618 | else |
| 619 | { |
| 620 | info.dxPosition.enableSystem("POSITION"); |
| 621 | } |
| 622 | |
| 623 | info.glPosition.enable(varyingSemantic, reservedRegisterIndex++); |
| 624 | |
| 625 | if (fragCoord) |
| 626 | { |
| 627 | info.glFragCoord.enable(varyingSemantic, reservedRegisterIndex++); |
| 628 | } |
| 629 | |
| 630 | if (pointCoord) |
| 631 | { |
| 632 | // SM3 reserves the TEXCOORD semantic for point sprite texcoords (gl_PointCoord) |
| 633 | // In D3D11 we manually compute gl_PointCoord in the GS. |
| 634 | if (hlsl4) |
| 635 | { |
| 636 | info.glPointCoord.enable(varyingSemantic, reservedRegisterIndex++); |
| 637 | } |
| 638 | else |
| 639 | { |
| 640 | info.glPointCoord.enable("TEXCOORD", 0); |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | // Special case: do not include PSIZE semantic in HLSL 3 pixel shaders |
| 645 | if (pointSize && (!pixelShader || hlsl4)) |
| 646 | { |
| 647 | info.glPointSize.enableSystem("PSIZE"); |
| 648 | } |
| 649 | |
| 650 | return info; |
| 651 | } |
| 652 | |
| 653 | std::string DynamicHLSL::generateVaryingLinkHLSL(const SemanticInfo &info, const std::string &varyingHLSL) const |
| 654 | { |
| 655 | std::string linkHLSL = "{\n"; |
| 656 | |
| 657 | ASSERT(info.dxPosition.enabled && info.glPosition.enabled); |
| 658 | |
| 659 | linkHLSL += " float4 dx_Position : " + info.dxPosition.str() + ";\n"; |
| 660 | linkHLSL += " float4 gl_Position : " + info.glPosition.str() + ";\n"; |
| 661 | |
| 662 | if (info.glFragCoord.enabled) |
| 663 | { |
| 664 | linkHLSL += " float4 gl_FragCoord : " + info.glFragCoord.str() + ";\n"; |
| 665 | } |
| 666 | |
| 667 | if (info.glPointCoord.enabled) |
| 668 | { |
| 669 | linkHLSL += " float2 gl_PointCoord : " + info.glPointCoord.str() + ";\n"; |
| 670 | } |
| 671 | |
| 672 | linkHLSL += varyingHLSL; |
| 673 | |
| 674 | if (info.glPointSize.enabled) |
| 675 | { |
| 676 | linkHLSL += " float gl_PointSize : " + info.glPointSize.str() + ";\n"; |
| 677 | } |
| 678 | |
| 679 | linkHLSL += "};\n"; |
| 680 | |
| 681 | return linkHLSL; |
| 682 | } |
| 683 | |
| 684 | void DynamicHLSL::storeBuiltinLinkedVaryings(const SemanticInfo &info, |
| 685 | std::vector<LinkedVarying> *linkedVaryings) const |
| 686 | { |
| 687 | ASSERT(info.glPosition.enabled); |
| 688 | |
| 689 | linkedVaryings->push_back(LinkedVarying("gl_Position", GL_FLOAT_VEC4, 1, info.glPosition.semantic, |
| 690 | info.glPosition.index, 1)); |
| 691 | |
| 692 | if (info.glFragCoord.enabled) |
| 693 | { |
| 694 | linkedVaryings->push_back(LinkedVarying("gl_FragCoord", GL_FLOAT_VEC4, 1, info.glFragCoord.semantic, |
| 695 | info.glFragCoord.index, 1)); |
| 696 | } |
| 697 | |
| 698 | if (info.glPointSize.enabled) |
| 699 | { |
| 700 | linkedVaryings->push_back(LinkedVarying("gl_PointSize", GL_FLOAT, 1, "PSIZE", 0, 1)); |
| 701 | } |
| 702 | } |
| 703 | |
Jamie Madill | 30d6c25 | 2014-11-13 10:03:33 -0500 | [diff] [blame] | 704 | void DynamicHLSL::storeUserLinkedVaryings(const ShaderD3D *vertexShader, |
Jamie Madill | febb7ad | 2014-06-18 13:50:51 -0400 | [diff] [blame] | 705 | std::vector<LinkedVarying> *linkedVaryings) const |
| 706 | { |
Brandon Jones | 7162096 | 2014-08-20 14:04:59 -0700 | [diff] [blame] | 707 | const std::string &varyingSemantic = getVaryingSemantic(vertexShader->mUsesPointSize); |
Jamie Madill | d15250e | 2014-09-03 09:40:44 -0400 | [diff] [blame] | 708 | const std::vector<PackedVarying> &varyings = vertexShader->getVaryings(); |
Jamie Madill | febb7ad | 2014-06-18 13:50:51 -0400 | [diff] [blame] | 709 | |
| 710 | for (unsigned int varyingIndex = 0; varyingIndex < varyings.size(); varyingIndex++) |
| 711 | { |
| 712 | const PackedVarying &varying = varyings[varyingIndex]; |
Jamie Madill | 54ad4f8 | 2014-09-03 09:40:46 -0400 | [diff] [blame] | 713 | |
Jamie Madill | febb7ad | 2014-06-18 13:50:51 -0400 | [diff] [blame] | 714 | if (varying.registerAssigned()) |
| 715 | { |
Jamie Madill | 54ad4f8 | 2014-09-03 09:40:46 -0400 | [diff] [blame] | 716 | ASSERT(!varying.isBuiltIn()); |
Jamie Madill | febb7ad | 2014-06-18 13:50:51 -0400 | [diff] [blame] | 717 | GLenum transposedType = TransposeMatrixType(varying.type); |
| 718 | int variableRows = (varying.isStruct() ? 1 : VariableRowCount(transposedType)); |
| 719 | |
| 720 | linkedVaryings->push_back(LinkedVarying(varying.name, varying.type, varying.elementCount(), |
| 721 | varyingSemantic, varying.registerIndex, |
| 722 | variableRows * varying.elementCount())); |
| 723 | } |
| 724 | } |
| 725 | } |
| 726 | |
Jamie Madill | de8892b | 2014-11-11 13:00:22 -0500 | [diff] [blame] | 727 | bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data, InfoLog &infoLog, int registers, |
| 728 | const VaryingPacking packing, |
| 729 | std::string &pixelHLSL, std::string &vertexHLSL, |
Jamie Madill | 30d6c25 | 2014-11-13 10:03:33 -0500 | [diff] [blame] | 730 | ShaderD3D *fragmentShader, ShaderD3D *vertexShader, |
Jamie Madill | de8892b | 2014-11-11 13:00:22 -0500 | [diff] [blame] | 731 | const std::vector<std::string> &transformFeedbackVaryings, |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 732 | std::vector<LinkedVarying> *linkedVaryings, |
Geoff Lang | 04fb89a | 2014-06-09 15:05:36 -0400 | [diff] [blame] | 733 | std::map<int, VariableLocation> *programOutputVars, |
Jamie Madill | f6be8d7 | 2014-09-05 10:38:07 -0400 | [diff] [blame] | 734 | std::vector<PixelShaderOutputVariable> *outPixelShaderKey, |
Geoff Lang | 04fb89a | 2014-06-09 15:05:36 -0400 | [diff] [blame] | 735 | bool *outUsesFragDepth) const |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 736 | { |
| 737 | if (pixelHLSL.empty() || vertexHLSL.empty()) |
| 738 | { |
| 739 | return false; |
| 740 | } |
| 741 | |
Brandon Jones | 7162096 | 2014-08-20 14:04:59 -0700 | [diff] [blame] | 742 | bool usesMRT = fragmentShader->mUsesMultipleRenderTargets; |
| 743 | bool usesFragColor = fragmentShader->mUsesFragColor; |
| 744 | bool usesFragData = fragmentShader->mUsesFragData; |
| 745 | bool usesFragCoord = fragmentShader->mUsesFragCoord; |
| 746 | bool usesPointCoord = fragmentShader->mUsesPointCoord; |
| 747 | bool usesPointSize = vertexShader->mUsesPointSize; |
Cooper Partin | e6664f0 | 2015-01-09 16:22:24 -0800 | [diff] [blame] | 748 | bool useInstancedPointSpriteEmulation = usesPointSize && mRenderer->getWorkarounds().useInstancedPointSpriteEmulation; |
Jamie Madill | febb7ad | 2014-06-18 13:50:51 -0400 | [diff] [blame] | 749 | |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 750 | if (usesFragColor && usesFragData) |
| 751 | { |
| 752 | infoLog.append("Cannot use both gl_FragColor and gl_FragData in the same fragment shader."); |
| 753 | return false; |
| 754 | } |
| 755 | |
| 756 | // Write the HLSL input/output declarations |
| 757 | const int shaderModel = mRenderer->getMajorShaderModel(); |
Jamie Madill | febb7ad | 2014-06-18 13:50:51 -0400 | [diff] [blame] | 758 | const int registersNeeded = registers + (usesFragCoord ? 1 : 0) + (usesPointCoord ? 1 : 0); |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 759 | |
| 760 | // Two cases when writing to gl_FragColor and using ESSL 1.0: |
| 761 | // - with a 3.0 context, the output color is copied to channel 0 |
| 762 | // - with a 2.0 context, the output color is broadcast to all channels |
Jamie Madill | de8892b | 2014-11-11 13:00:22 -0500 | [diff] [blame] | 763 | const bool broadcast = (fragmentShader->mUsesFragColor && data.clientVersion < 3); |
| 764 | const unsigned int numRenderTargets = (broadcast || usesMRT ? data.caps->maxDrawBuffers : 1); |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 765 | |
Brandon Jones | 7162096 | 2014-08-20 14:04:59 -0700 | [diff] [blame] | 766 | int shaderVersion = vertexShader->getShaderVersion(); |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 767 | |
Jamie Madill | de8892b | 2014-11-11 13:00:22 -0500 | [diff] [blame] | 768 | if (static_cast<GLuint>(registersNeeded) > data.caps->maxVaryingVectors) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 769 | { |
| 770 | infoLog.append("No varying registers left to support gl_FragCoord/gl_PointCoord"); |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 771 | return false; |
| 772 | } |
| 773 | |
Jamie Madill | febb7ad | 2014-06-18 13:50:51 -0400 | [diff] [blame] | 774 | const std::string &varyingHLSL = generateVaryingHLSL(vertexShader); |
Cooper Partin | e6664f0 | 2015-01-09 16:22:24 -0800 | [diff] [blame] | 775 | |
| 776 | // Instanced PointSprite emulation requires that gl_PointCoord is present in the vertex shader VS_OUTPUT |
| 777 | // structure to ensure compatibility with the generated PS_INPUT of the pixel shader. |
| 778 | // GeometryShader PointSprite emulation does not require this additional entry because the |
| 779 | // GS_OUTPUT of the Geometry shader contains the pointCoord value and already matches the PS_INPUT of the |
| 780 | // generated pixel shader. |
Jamie Madill | febb7ad | 2014-06-18 13:50:51 -0400 | [diff] [blame] | 781 | const SemanticInfo &vertexSemantics = getSemanticInfo(registers, usesFragCoord, |
Cooper Partin | e6664f0 | 2015-01-09 16:22:24 -0800 | [diff] [blame] | 782 | (useInstancedPointSpriteEmulation && usesPointCoord), |
| 783 | usesPointSize, false); |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 784 | |
Jamie Madill | febb7ad | 2014-06-18 13:50:51 -0400 | [diff] [blame] | 785 | storeUserLinkedVaryings(vertexShader, linkedVaryings); |
| 786 | storeBuiltinLinkedVaryings(vertexSemantics, linkedVaryings); |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 787 | |
Cooper Partin | e6664f0 | 2015-01-09 16:22:24 -0800 | [diff] [blame] | 788 | // Instanced PointSprite emulation requires additional entries originally generated in the |
| 789 | // GeometryShader HLSL. These include pointsize clamp values. |
| 790 | if (useInstancedPointSpriteEmulation) |
| 791 | { |
| 792 | vertexHLSL += "static float minPointSize = " + Str((int)mRenderer->getRendererCaps().minAliasedPointSize) + ".0f;\n" |
| 793 | "static float maxPointSize = " + Str((int)mRenderer->getRendererCaps().maxAliasedPointSize) + ".0f;\n"; |
| 794 | } |
| 795 | |
Jamie Madill | c5ede1a | 2014-02-14 16:41:27 -0500 | [diff] [blame] | 796 | // Add stub string to be replaced when shader is dynamically defined by its layout |
Jamie Madill | febb7ad | 2014-06-18 13:50:51 -0400 | [diff] [blame] | 797 | vertexHLSL += "\n" + VERTEX_ATTRIBUTE_STUB_STRING + "\n" |
| 798 | "struct VS_OUTPUT\n" + generateVaryingLinkHLSL(vertexSemantics, varyingHLSL) + "\n" |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 799 | "VS_OUTPUT main(VS_INPUT input)\n" |
Jamie Madill | c5ede1a | 2014-02-14 16:41:27 -0500 | [diff] [blame] | 800 | "{\n" |
| 801 | " initAttributes(input);\n"; |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 802 | |
Jamie Madill | 3799714 | 2015-01-28 10:06:34 -0500 | [diff] [blame] | 803 | if (vertexShader->usesDeferredInit()) |
| 804 | { |
| 805 | vertexHLSL += "\n" |
| 806 | " initializeDeferredGlobals();\n"; |
| 807 | } |
| 808 | |
| 809 | vertexHLSL += "\n" |
| 810 | " gl_main();\n" |
| 811 | "\n" |
| 812 | " VS_OUTPUT output;\n" |
| 813 | " output.gl_Position = gl_Position;\n"; |
| 814 | |
Austin Kinross | 4fd18b1 | 2014-12-22 12:32:05 -0800 | [diff] [blame] | 815 | // On D3D9 or D3D11 Feature Level 9, we need to emulate large viewports using dx_ViewAdjust. |
| 816 | if (shaderModel >= 4 && mRenderer->getShaderModelSuffix() == "") |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 817 | { |
Jamie Madill | 3799714 | 2015-01-28 10:06:34 -0500 | [diff] [blame] | 818 | vertexHLSL += " output.dx_Position.x = gl_Position.x;\n" |
Jamie Madill | 2bf8b37 | 2014-06-16 17:18:51 -0400 | [diff] [blame] | 819 | " output.dx_Position.y = -gl_Position.y;\n" |
| 820 | " output.dx_Position.z = (gl_Position.z + gl_Position.w) * 0.5;\n" |
| 821 | " output.dx_Position.w = gl_Position.w;\n"; |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 822 | } |
| 823 | else |
| 824 | { |
Jamie Madill | 3799714 | 2015-01-28 10:06:34 -0500 | [diff] [blame] | 825 | vertexHLSL += " output.dx_Position.x = gl_Position.x * dx_ViewAdjust.z + dx_ViewAdjust.x * gl_Position.w;\n" |
Jamie Madill | 2bf8b37 | 2014-06-16 17:18:51 -0400 | [diff] [blame] | 826 | " output.dx_Position.y = -(gl_Position.y * dx_ViewAdjust.w + dx_ViewAdjust.y * gl_Position.w);\n" |
| 827 | " output.dx_Position.z = (gl_Position.z + gl_Position.w) * 0.5;\n" |
| 828 | " output.dx_Position.w = gl_Position.w;\n"; |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 829 | } |
| 830 | |
Jamie Madill | febb7ad | 2014-06-18 13:50:51 -0400 | [diff] [blame] | 831 | if (usesPointSize && shaderModel >= 3) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 832 | { |
| 833 | vertexHLSL += " output.gl_PointSize = gl_PointSize;\n"; |
| 834 | } |
| 835 | |
Jamie Madill | febb7ad | 2014-06-18 13:50:51 -0400 | [diff] [blame] | 836 | if (usesFragCoord) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 837 | { |
| 838 | vertexHLSL += " output.gl_FragCoord = gl_Position;\n"; |
| 839 | } |
| 840 | |
Jamie Madill | d15250e | 2014-09-03 09:40:44 -0400 | [diff] [blame] | 841 | const std::vector<PackedVarying> &vertexVaryings = vertexShader->getVaryings(); |
| 842 | for (unsigned int vertVaryingIndex = 0; vertVaryingIndex < vertexVaryings.size(); vertVaryingIndex++) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 843 | { |
Jamie Madill | d15250e | 2014-09-03 09:40:44 -0400 | [diff] [blame] | 844 | const PackedVarying &varying = vertexVaryings[vertVaryingIndex]; |
Jamie Madill | ff0d2ba | 2014-05-14 13:49:10 -0400 | [diff] [blame] | 845 | if (varying.registerAssigned()) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 846 | { |
Jamie Madill | ff0d2ba | 2014-05-14 13:49:10 -0400 | [diff] [blame] | 847 | for (unsigned int elementIndex = 0; elementIndex < varying.elementCount(); elementIndex++) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 848 | { |
Jamie Madill | ff0d2ba | 2014-05-14 13:49:10 -0400 | [diff] [blame] | 849 | int variableRows = (varying.isStruct() ? 1 : VariableRowCount(TransposeMatrixType(varying.type))); |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 850 | |
| 851 | for (int row = 0; row < variableRows; row++) |
| 852 | { |
Jamie Madill | de8892b | 2014-11-11 13:00:22 -0500 | [diff] [blame] | 853 | int r = varying.registerIndex + varying.columnIndex * data.caps->maxVaryingVectors + elementIndex * variableRows + row; |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 854 | vertexHLSL += " output.v" + Str(r); |
| 855 | |
Jamie Madill | ff0d2ba | 2014-05-14 13:49:10 -0400 | [diff] [blame] | 856 | vertexHLSL += " = _" + varying.name; |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 857 | |
Jamie Madill | ff0d2ba | 2014-05-14 13:49:10 -0400 | [diff] [blame] | 858 | if (varying.isArray()) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 859 | { |
| 860 | vertexHLSL += ArrayString(elementIndex); |
| 861 | } |
| 862 | |
| 863 | if (variableRows > 1) |
| 864 | { |
| 865 | vertexHLSL += ArrayString(row); |
| 866 | } |
| 867 | |
| 868 | vertexHLSL += ";\n"; |
| 869 | } |
| 870 | } |
| 871 | } |
| 872 | } |
| 873 | |
Cooper Partin | e6664f0 | 2015-01-09 16:22:24 -0800 | [diff] [blame] | 874 | // Instanced PointSprite emulation requires additional entries to calculate |
| 875 | // the final output vertex positions of the quad that represents each sprite. |
| 876 | if (useInstancedPointSpriteEmulation) |
| 877 | { |
| 878 | vertexHLSL += "\n" |
| 879 | " gl_PointSize = clamp(gl_PointSize, minPointSize, maxPointSize);\n" |
| 880 | " 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" |
| 881 | " output.gl_PointSize = gl_PointSize;\n"; |
| 882 | |
| 883 | if (usesPointCoord) |
| 884 | { |
| 885 | vertexHLSL += "\n" |
| 886 | " output.gl_PointCoord = input.spriteTexCoord;\n"; |
| 887 | } |
| 888 | } |
| 889 | |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 890 | vertexHLSL += "\n" |
| 891 | " return output;\n" |
| 892 | "}\n"; |
| 893 | |
Jamie Madill | febb7ad | 2014-06-18 13:50:51 -0400 | [diff] [blame] | 894 | const SemanticInfo &pixelSemantics = getSemanticInfo(registers, usesFragCoord, usesPointCoord, |
| 895 | usesPointSize, true); |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 896 | |
Jamie Madill | febb7ad | 2014-06-18 13:50:51 -0400 | [diff] [blame] | 897 | pixelHLSL += "struct PS_INPUT\n" + generateVaryingLinkHLSL(pixelSemantics, varyingHLSL) + "\n"; |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 898 | |
| 899 | if (shaderVersion < 300) |
| 900 | { |
| 901 | for (unsigned int renderTargetIndex = 0; renderTargetIndex < numRenderTargets; renderTargetIndex++) |
| 902 | { |
Jamie Madill | f6be8d7 | 2014-09-05 10:38:07 -0400 | [diff] [blame] | 903 | PixelShaderOutputVariable outputKeyVariable; |
Geoff Lang | 04fb89a | 2014-06-09 15:05:36 -0400 | [diff] [blame] | 904 | outputKeyVariable.type = GL_FLOAT_VEC4; |
| 905 | outputKeyVariable.name = "gl_Color" + Str(renderTargetIndex); |
| 906 | outputKeyVariable.source = broadcast ? "gl_Color[0]" : "gl_Color[" + Str(renderTargetIndex) + "]"; |
| 907 | outputKeyVariable.outputIndex = renderTargetIndex; |
| 908 | |
| 909 | outPixelShaderKey->push_back(outputKeyVariable); |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 910 | } |
| 911 | |
Brandon Jones | 7162096 | 2014-08-20 14:04:59 -0700 | [diff] [blame] | 912 | *outUsesFragDepth = fragmentShader->mUsesFragDepth; |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 913 | } |
| 914 | else |
| 915 | { |
| 916 | defineOutputVariables(fragmentShader, programOutputVars); |
| 917 | |
Jamie Madill | d15250e | 2014-09-03 09:40:44 -0400 | [diff] [blame] | 918 | const std::vector<sh::Attribute> &shaderOutputVars = fragmentShader->getActiveOutputVariables(); |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 919 | for (auto locationIt = programOutputVars->begin(); locationIt != programOutputVars->end(); locationIt++) |
| 920 | { |
| 921 | const VariableLocation &outputLocation = locationIt->second; |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 922 | const sh::ShaderVariable &outputVariable = shaderOutputVars[outputLocation.index]; |
Geoff Lang | 04fb89a | 2014-06-09 15:05:36 -0400 | [diff] [blame] | 923 | const std::string &variableName = "out_" + outputLocation.name; |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 924 | const std::string &elementString = (outputLocation.element == GL_INVALID_INDEX ? "" : Str(outputLocation.element)); |
| 925 | |
Jamie Madill | 54ad4f8 | 2014-09-03 09:40:46 -0400 | [diff] [blame] | 926 | ASSERT(outputVariable.staticUse); |
| 927 | |
Jamie Madill | f6be8d7 | 2014-09-05 10:38:07 -0400 | [diff] [blame] | 928 | PixelShaderOutputVariable outputKeyVariable; |
Geoff Lang | 04fb89a | 2014-06-09 15:05:36 -0400 | [diff] [blame] | 929 | outputKeyVariable.type = outputVariable.type; |
| 930 | outputKeyVariable.name = variableName + elementString; |
| 931 | outputKeyVariable.source = variableName + ArrayString(outputLocation.element); |
| 932 | outputKeyVariable.outputIndex = locationIt->first; |
| 933 | |
| 934 | outPixelShaderKey->push_back(outputKeyVariable); |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 935 | } |
Geoff Lang | 04fb89a | 2014-06-09 15:05:36 -0400 | [diff] [blame] | 936 | |
| 937 | *outUsesFragDepth = false; |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 938 | } |
| 939 | |
Geoff Lang | 04fb89a | 2014-06-09 15:05:36 -0400 | [diff] [blame] | 940 | pixelHLSL += PIXEL_OUTPUT_STUB_STRING + "\n"; |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 941 | |
Brandon Jones | 7162096 | 2014-08-20 14:04:59 -0700 | [diff] [blame] | 942 | if (fragmentShader->mUsesFrontFacing) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 943 | { |
| 944 | if (shaderModel >= 4) |
| 945 | { |
| 946 | pixelHLSL += "PS_OUTPUT main(PS_INPUT input, bool isFrontFace : SV_IsFrontFace)\n" |
| 947 | "{\n"; |
| 948 | } |
| 949 | else |
| 950 | { |
| 951 | pixelHLSL += "PS_OUTPUT main(PS_INPUT input, float vFace : VFACE)\n" |
| 952 | "{\n"; |
| 953 | } |
| 954 | } |
| 955 | else |
| 956 | { |
| 957 | pixelHLSL += "PS_OUTPUT main(PS_INPUT input)\n" |
| 958 | "{\n"; |
| 959 | } |
| 960 | |
Jamie Madill | febb7ad | 2014-06-18 13:50:51 -0400 | [diff] [blame] | 961 | if (usesFragCoord) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 962 | { |
| 963 | pixelHLSL += " float rhw = 1.0 / input.gl_FragCoord.w;\n"; |
| 964 | |
Austin Kinross | 588434c | 2014-12-10 10:41:45 -0800 | [diff] [blame] | 965 | // Certain Shader Models (4_0+ and 3_0) allow reading from dx_Position in the pixel shader. |
| 966 | // Other Shader Models (4_0_level_9_3 and 2_x) don't support this, so we emulate it using dx_ViewCoords. |
| 967 | if (shaderModel >= 4 && mRenderer->getShaderModelSuffix() == "") |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 968 | { |
Jamie Madill | febb7ad | 2014-06-18 13:50:51 -0400 | [diff] [blame] | 969 | pixelHLSL += " gl_FragCoord.x = input.dx_Position.x;\n" |
| 970 | " gl_FragCoord.y = input.dx_Position.y;\n"; |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 971 | } |
Austin Kinross | 588434c | 2014-12-10 10:41:45 -0800 | [diff] [blame] | 972 | else if (shaderModel == 3) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 973 | { |
Jamie Madill | febb7ad | 2014-06-18 13:50:51 -0400 | [diff] [blame] | 974 | pixelHLSL += " gl_FragCoord.x = input.dx_Position.x + 0.5;\n" |
| 975 | " gl_FragCoord.y = input.dx_Position.y + 0.5;\n"; |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 976 | } |
| 977 | else |
| 978 | { |
| 979 | // dx_ViewCoords contains the viewport width/2, height/2, center.x and center.y. See Renderer::setViewport() |
| 980 | pixelHLSL += " gl_FragCoord.x = (input.gl_FragCoord.x * rhw) * dx_ViewCoords.x + dx_ViewCoords.z;\n" |
| 981 | " gl_FragCoord.y = (input.gl_FragCoord.y * rhw) * dx_ViewCoords.y + dx_ViewCoords.w;\n"; |
| 982 | } |
| 983 | |
| 984 | pixelHLSL += " gl_FragCoord.z = (input.gl_FragCoord.z * rhw) * dx_DepthFront.x + dx_DepthFront.y;\n" |
| 985 | " gl_FragCoord.w = rhw;\n"; |
| 986 | } |
| 987 | |
Jamie Madill | febb7ad | 2014-06-18 13:50:51 -0400 | [diff] [blame] | 988 | if (usesPointCoord && shaderModel >= 3) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 989 | { |
| 990 | pixelHLSL += " gl_PointCoord.x = input.gl_PointCoord.x;\n"; |
| 991 | pixelHLSL += " gl_PointCoord.y = 1.0 - input.gl_PointCoord.y;\n"; |
| 992 | } |
| 993 | |
Brandon Jones | 7162096 | 2014-08-20 14:04:59 -0700 | [diff] [blame] | 994 | if (fragmentShader->mUsesFrontFacing) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 995 | { |
| 996 | if (shaderModel <= 3) |
| 997 | { |
| 998 | pixelHLSL += " gl_FrontFacing = (vFace * dx_DepthFront.z >= 0.0);\n"; |
| 999 | } |
| 1000 | else |
| 1001 | { |
| 1002 | pixelHLSL += " gl_FrontFacing = isFrontFace;\n"; |
| 1003 | } |
| 1004 | } |
| 1005 | |
Jamie Madill | d15250e | 2014-09-03 09:40:44 -0400 | [diff] [blame] | 1006 | const std::vector<PackedVarying> &fragmentVaryings = fragmentShader->getVaryings(); |
| 1007 | for (unsigned int varyingIndex = 0; varyingIndex < fragmentVaryings.size(); varyingIndex++) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1008 | { |
Jamie Madill | d15250e | 2014-09-03 09:40:44 -0400 | [diff] [blame] | 1009 | const PackedVarying &varying = fragmentVaryings[varyingIndex]; |
Jamie Madill | ff0d2ba | 2014-05-14 13:49:10 -0400 | [diff] [blame] | 1010 | if (varying.registerAssigned()) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1011 | { |
Jamie Madill | 54ad4f8 | 2014-09-03 09:40:46 -0400 | [diff] [blame] | 1012 | ASSERT(!varying.isBuiltIn()); |
Jamie Madill | ff0d2ba | 2014-05-14 13:49:10 -0400 | [diff] [blame] | 1013 | for (unsigned int elementIndex = 0; elementIndex < varying.elementCount(); elementIndex++) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1014 | { |
Jamie Madill | ff0d2ba | 2014-05-14 13:49:10 -0400 | [diff] [blame] | 1015 | GLenum transposedType = TransposeMatrixType(varying.type); |
| 1016 | int variableRows = (varying.isStruct() ? 1 : VariableRowCount(transposedType)); |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1017 | for (int row = 0; row < variableRows; row++) |
| 1018 | { |
Jamie Madill | de8892b | 2014-11-11 13:00:22 -0500 | [diff] [blame] | 1019 | std::string n = Str(varying.registerIndex + varying.columnIndex * data.caps->maxVaryingVectors + elementIndex * variableRows + row); |
Jamie Madill | ff0d2ba | 2014-05-14 13:49:10 -0400 | [diff] [blame] | 1020 | pixelHLSL += " _" + varying.name; |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1021 | |
Jamie Madill | ff0d2ba | 2014-05-14 13:49:10 -0400 | [diff] [blame] | 1022 | if (varying.isArray()) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1023 | { |
| 1024 | pixelHLSL += ArrayString(elementIndex); |
| 1025 | } |
| 1026 | |
| 1027 | if (variableRows > 1) |
| 1028 | { |
| 1029 | pixelHLSL += ArrayString(row); |
| 1030 | } |
| 1031 | |
Jamie Madill | ff0d2ba | 2014-05-14 13:49:10 -0400 | [diff] [blame] | 1032 | if (varying.isStruct()) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1033 | { |
| 1034 | pixelHLSL += " = input.v" + n + ";\n"; break; |
| 1035 | } |
| 1036 | else |
| 1037 | { |
| 1038 | switch (VariableColumnCount(transposedType)) |
| 1039 | { |
| 1040 | case 1: pixelHLSL += " = input.v" + n + ".x;\n"; break; |
| 1041 | case 2: pixelHLSL += " = input.v" + n + ".xy;\n"; break; |
| 1042 | case 3: pixelHLSL += " = input.v" + n + ".xyz;\n"; break; |
| 1043 | case 4: pixelHLSL += " = input.v" + n + ";\n"; break; |
| 1044 | default: UNREACHABLE(); |
| 1045 | } |
| 1046 | } |
| 1047 | } |
| 1048 | } |
| 1049 | } |
Jamie Madill | 54ad4f8 | 2014-09-03 09:40:46 -0400 | [diff] [blame] | 1050 | else |
| 1051 | { |
| 1052 | ASSERT(varying.isBuiltIn() || !varying.staticUse); |
| 1053 | } |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1054 | } |
| 1055 | |
Jamie Madill | 3799714 | 2015-01-28 10:06:34 -0500 | [diff] [blame] | 1056 | if (fragmentShader->usesDeferredInit()) |
| 1057 | { |
| 1058 | pixelHLSL += "\n" |
| 1059 | " initializeDeferredGlobals();\n"; |
| 1060 | } |
| 1061 | |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1062 | pixelHLSL += "\n" |
| 1063 | " gl_main();\n" |
| 1064 | "\n" |
Geoff Lang | 04fb89a | 2014-06-09 15:05:36 -0400 | [diff] [blame] | 1065 | " return generateOutput();\n" |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1066 | "}\n"; |
| 1067 | |
| 1068 | return true; |
| 1069 | } |
| 1070 | |
Jamie Madill | 30d6c25 | 2014-11-13 10:03:33 -0500 | [diff] [blame] | 1071 | void DynamicHLSL::defineOutputVariables(ShaderD3D *fragmentShader, std::map<int, VariableLocation> *programOutputVars) const |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1072 | { |
Jamie Madill | d15250e | 2014-09-03 09:40:44 -0400 | [diff] [blame] | 1073 | const std::vector<sh::Attribute> &shaderOutputVars = fragmentShader->getActiveOutputVariables(); |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1074 | |
| 1075 | for (unsigned int outputVariableIndex = 0; outputVariableIndex < shaderOutputVars.size(); outputVariableIndex++) |
| 1076 | { |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 1077 | const sh::Attribute &outputVariable = shaderOutputVars[outputVariableIndex]; |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1078 | const int baseLocation = outputVariable.location == -1 ? 0 : outputVariable.location; |
| 1079 | |
Jamie Madill | 54ad4f8 | 2014-09-03 09:40:46 -0400 | [diff] [blame] | 1080 | ASSERT(outputVariable.staticUse); |
| 1081 | |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1082 | if (outputVariable.arraySize > 0) |
| 1083 | { |
| 1084 | for (unsigned int elementIndex = 0; elementIndex < outputVariable.arraySize; elementIndex++) |
| 1085 | { |
| 1086 | const int location = baseLocation + elementIndex; |
| 1087 | ASSERT(programOutputVars->count(location) == 0); |
| 1088 | (*programOutputVars)[location] = VariableLocation(outputVariable.name, elementIndex, outputVariableIndex); |
| 1089 | } |
| 1090 | } |
| 1091 | else |
| 1092 | { |
| 1093 | ASSERT(programOutputVars->count(baseLocation) == 0); |
| 1094 | (*programOutputVars)[baseLocation] = VariableLocation(outputVariable.name, GL_INVALID_INDEX, outputVariableIndex); |
| 1095 | } |
| 1096 | } |
| 1097 | } |
| 1098 | |
Jamie Madill | 30d6c25 | 2014-11-13 10:03:33 -0500 | [diff] [blame] | 1099 | std::string DynamicHLSL::generateGeometryShaderHLSL(int registers, ShaderD3D *fragmentShader, ShaderD3D *vertexShader) const |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1100 | { |
| 1101 | // for now we only handle point sprite emulation |
Brandon Jones | 7162096 | 2014-08-20 14:04:59 -0700 | [diff] [blame] | 1102 | ASSERT(vertexShader->mUsesPointSize && mRenderer->getMajorShaderModel() >= 4); |
Jamie Madill | ff0d2ba | 2014-05-14 13:49:10 -0400 | [diff] [blame] | 1103 | return generatePointSpriteHLSL(registers, fragmentShader, vertexShader); |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1104 | } |
| 1105 | |
Jamie Madill | 30d6c25 | 2014-11-13 10:03:33 -0500 | [diff] [blame] | 1106 | std::string DynamicHLSL::generatePointSpriteHLSL(int registers, ShaderD3D *fragmentShader, ShaderD3D *vertexShader) const |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1107 | { |
| 1108 | ASSERT(registers >= 0); |
Brandon Jones | 7162096 | 2014-08-20 14:04:59 -0700 | [diff] [blame] | 1109 | ASSERT(vertexShader->mUsesPointSize); |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1110 | ASSERT(mRenderer->getMajorShaderModel() >= 4); |
| 1111 | |
| 1112 | std::string geomHLSL; |
| 1113 | |
Brandon Jones | 7162096 | 2014-08-20 14:04:59 -0700 | [diff] [blame] | 1114 | const SemanticInfo &inSemantics = getSemanticInfo(registers, fragmentShader->mUsesFragCoord, |
Jamie Madill | febb7ad | 2014-06-18 13:50:51 -0400 | [diff] [blame] | 1115 | false, true, false); |
Brandon Jones | 7162096 | 2014-08-20 14:04:59 -0700 | [diff] [blame] | 1116 | const SemanticInfo &outSemantics = getSemanticInfo(registers, fragmentShader->mUsesFragCoord, |
| 1117 | fragmentShader->mUsesPointCoord, true, false); |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1118 | |
Jamie Madill | febb7ad | 2014-06-18 13:50:51 -0400 | [diff] [blame] | 1119 | std::string varyingHLSL = generateVaryingHLSL(vertexShader); |
| 1120 | std::string inLinkHLSL = generateVaryingLinkHLSL(inSemantics, varyingHLSL); |
| 1121 | std::string outLinkHLSL = generateVaryingLinkHLSL(outSemantics, varyingHLSL); |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1122 | |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1123 | // TODO(geofflang): use context's caps |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1124 | geomHLSL += "uniform float4 dx_ViewCoords : register(c1);\n" |
| 1125 | "\n" |
Jamie Madill | febb7ad | 2014-06-18 13:50:51 -0400 | [diff] [blame] | 1126 | "struct GS_INPUT\n" + inLinkHLSL + "\n" + |
| 1127 | "struct GS_OUTPUT\n" + outLinkHLSL + "\n" + |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1128 | "\n" |
Jamie Madill | 3799714 | 2015-01-28 10:06:34 -0500 | [diff] [blame] | 1129 | "static float2 pointSpriteCorners[] = \n" |
| 1130 | "{\n" |
| 1131 | " float2( 0.5f, -0.5f),\n" |
| 1132 | " float2( 0.5f, 0.5f),\n" |
| 1133 | " float2(-0.5f, -0.5f),\n" |
| 1134 | " float2(-0.5f, 0.5f)\n" |
| 1135 | "};\n" |
| 1136 | "\n" |
| 1137 | "static float2 pointSpriteTexcoords[] = \n" |
| 1138 | "{\n" |
| 1139 | " float2(1.0f, 1.0f),\n" |
| 1140 | " float2(1.0f, 0.0f),\n" |
| 1141 | " float2(0.0f, 1.0f),\n" |
| 1142 | " float2(0.0f, 0.0f)\n" |
| 1143 | "};\n" |
| 1144 | "\n" |
| 1145 | "static float minPointSize = " + Str(mRenderer->getRendererCaps().minAliasedPointSize) + ".0f;\n" |
| 1146 | "static float maxPointSize = " + Str(mRenderer->getRendererCaps().maxAliasedPointSize) + ".0f;\n" |
| 1147 | "\n" |
| 1148 | "[maxvertexcount(4)]\n" |
| 1149 | "void main(point GS_INPUT input[1], inout TriangleStream<GS_OUTPUT> outStream)\n" |
| 1150 | "{\n" |
| 1151 | " GS_OUTPUT output = (GS_OUTPUT)0;\n" |
| 1152 | " output.gl_Position = input[0].gl_Position;\n" |
| 1153 | " output.gl_PointSize = input[0].gl_PointSize;\n"; |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1154 | |
| 1155 | for (int r = 0; r < registers; r++) |
| 1156 | { |
| 1157 | geomHLSL += " output.v" + Str(r) + " = input[0].v" + Str(r) + ";\n"; |
| 1158 | } |
| 1159 | |
Brandon Jones | 7162096 | 2014-08-20 14:04:59 -0700 | [diff] [blame] | 1160 | if (fragmentShader->mUsesFragCoord) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1161 | { |
| 1162 | geomHLSL += " output.gl_FragCoord = input[0].gl_FragCoord;\n"; |
| 1163 | } |
| 1164 | |
| 1165 | geomHLSL += " \n" |
| 1166 | " float gl_PointSize = clamp(input[0].gl_PointSize, minPointSize, maxPointSize);\n" |
Jamie Madill | febb7ad | 2014-06-18 13:50:51 -0400 | [diff] [blame] | 1167 | " float4 dx_Position = input[0].dx_Position;\n" |
| 1168 | " float2 viewportScale = float2(1.0f / dx_ViewCoords.x, 1.0f / dx_ViewCoords.y) * dx_Position.w;\n"; |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1169 | |
| 1170 | for (int corner = 0; corner < 4; corner++) |
| 1171 | { |
| 1172 | geomHLSL += " \n" |
Jamie Madill | febb7ad | 2014-06-18 13:50:51 -0400 | [diff] [blame] | 1173 | " output.dx_Position = dx_Position + float4(pointSpriteCorners[" + Str(corner) + "] * viewportScale * gl_PointSize, 0.0f, 0.0f);\n"; |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1174 | |
Brandon Jones | 7162096 | 2014-08-20 14:04:59 -0700 | [diff] [blame] | 1175 | if (fragmentShader->mUsesPointCoord) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1176 | { |
| 1177 | geomHLSL += " output.gl_PointCoord = pointSpriteTexcoords[" + Str(corner) + "];\n"; |
| 1178 | } |
| 1179 | |
| 1180 | geomHLSL += " outStream.Append(output);\n"; |
| 1181 | } |
| 1182 | |
| 1183 | geomHLSL += " \n" |
| 1184 | " outStream.RestartStrip();\n" |
| 1185 | "}\n"; |
| 1186 | |
| 1187 | return geomHLSL; |
| 1188 | } |
| 1189 | |
| 1190 | // This method needs to match OutputHLSL::decorate |
Jamie Madill | a53ab51 | 2014-03-17 09:47:44 -0400 | [diff] [blame] | 1191 | std::string DynamicHLSL::decorateVariable(const std::string &name) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1192 | { |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 1193 | if (name.compare(0, 3, "gl_") != 0) |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1194 | { |
| 1195 | return "_" + name; |
| 1196 | } |
| 1197 | |
| 1198 | return name; |
| 1199 | } |
| 1200 | |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 1201 | std::string DynamicHLSL::generateAttributeConversionHLSL(const VertexFormat &vertexFormat, const sh::ShaderVariable &shaderAttrib) const |
Jamie Madill | c5ede1a | 2014-02-14 16:41:27 -0500 | [diff] [blame] | 1202 | { |
Jamie Madill | a53ab51 | 2014-03-17 09:47:44 -0400 | [diff] [blame] | 1203 | std::string attribString = "input." + decorateVariable(shaderAttrib.name); |
Jamie Madill | 8664b06 | 2014-02-14 16:41:29 -0500 | [diff] [blame] | 1204 | |
Jamie Madill | c5ede1a | 2014-02-14 16:41:27 -0500 | [diff] [blame] | 1205 | // Matrix |
| 1206 | if (IsMatrixType(shaderAttrib.type)) |
| 1207 | { |
Jamie Madill | 8664b06 | 2014-02-14 16:41:29 -0500 | [diff] [blame] | 1208 | return "transpose(" + attribString + ")"; |
Jamie Madill | c5ede1a | 2014-02-14 16:41:27 -0500 | [diff] [blame] | 1209 | } |
| 1210 | |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 1211 | GLenum shaderComponentType = VariableComponentType(shaderAttrib.type); |
| 1212 | int shaderComponentCount = VariableComponentCount(shaderAttrib.type); |
Jamie Madill | 8664b06 | 2014-02-14 16:41:29 -0500 | [diff] [blame] | 1213 | |
Jamie Madill | 8664b06 | 2014-02-14 16:41:29 -0500 | [diff] [blame] | 1214 | // Perform integer to float conversion (if necessary) |
| 1215 | bool requiresTypeConversion = (shaderComponentType == GL_FLOAT && vertexFormat.mType != GL_FLOAT); |
| 1216 | |
Jamie Madill | 7a29e4a | 2014-05-02 10:41:48 -0400 | [diff] [blame] | 1217 | if (requiresTypeConversion) |
Jamie Madill | 8664b06 | 2014-02-14 16:41:29 -0500 | [diff] [blame] | 1218 | { |
Jamie Madill | 7a29e4a | 2014-05-02 10:41:48 -0400 | [diff] [blame] | 1219 | // TODO: normalization for 32-bit integer formats |
| 1220 | ASSERT(!vertexFormat.mNormalized && !vertexFormat.mPureInteger); |
| 1221 | return "float" + Str(shaderComponentCount) + "(" + attribString + ")"; |
Jamie Madill | 8664b06 | 2014-02-14 16:41:29 -0500 | [diff] [blame] | 1222 | } |
Jamie Madill | c5ede1a | 2014-02-14 16:41:27 -0500 | [diff] [blame] | 1223 | |
| 1224 | // No conversion necessary |
Jamie Madill | 8664b06 | 2014-02-14 16:41:29 -0500 | [diff] [blame] | 1225 | return attribString; |
Jamie Madill | c5ede1a | 2014-02-14 16:41:27 -0500 | [diff] [blame] | 1226 | } |
| 1227 | |
Jamie Madill | 7a29e4a | 2014-05-02 10:41:48 -0400 | [diff] [blame] | 1228 | void DynamicHLSL::getInputLayoutSignature(const VertexFormat inputLayout[], GLenum signature[]) const |
| 1229 | { |
| 1230 | for (size_t inputIndex = 0; inputIndex < MAX_VERTEX_ATTRIBS; inputIndex++) |
| 1231 | { |
| 1232 | const VertexFormat &vertexFormat = inputLayout[inputIndex]; |
| 1233 | |
| 1234 | if (vertexFormat.mType == GL_NONE) |
| 1235 | { |
| 1236 | signature[inputIndex] = GL_NONE; |
| 1237 | } |
| 1238 | else |
| 1239 | { |
Jamie Madill | 30d6c25 | 2014-11-13 10:03:33 -0500 | [diff] [blame] | 1240 | bool gpuConverted = ((mRenderer->getVertexConversionType(vertexFormat) & VERTEX_CONVERT_GPU) != 0); |
Jamie Madill | 7a29e4a | 2014-05-02 10:41:48 -0400 | [diff] [blame] | 1241 | signature[inputIndex] = (gpuConverted ? GL_TRUE : GL_FALSE); |
| 1242 | } |
| 1243 | } |
| 1244 | } |
| 1245 | |
Jamie Madill | 5f56273 | 2014-02-14 16:41:24 -0500 | [diff] [blame] | 1246 | } |