Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [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 | |
| 7 | // ProgramD3D.cpp: Defines the rx::ProgramD3D class which implements rx::ProgramImpl. |
| 8 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 9 | #include "libANGLE/renderer/d3d/ProgramD3D.h" |
Jamie Madill | 437d266 | 2014-12-05 14:23:35 -0500 | [diff] [blame] | 10 | |
| 11 | #include "common/utilities.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 12 | #include "libANGLE/Framebuffer.h" |
| 13 | #include "libANGLE/FramebufferAttachment.h" |
| 14 | #include "libANGLE/Program.h" |
Jamie Madill | 6df9b37 | 2015-02-18 21:28:19 +0000 | [diff] [blame] | 15 | #include "libANGLE/features.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 16 | #include "libANGLE/renderer/d3d/DynamicHLSL.h" |
Jamie Madill | 85a1804 | 2015-03-05 15:41:41 -0500 | [diff] [blame] | 17 | #include "libANGLE/renderer/d3d/FramebufferD3D.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 18 | #include "libANGLE/renderer/d3d/RendererD3D.h" |
| 19 | #include "libANGLE/renderer/d3d/ShaderD3D.h" |
Geoff Lang | 359ef26 | 2015-01-05 14:42:29 -0500 | [diff] [blame] | 20 | #include "libANGLE/renderer/d3d/ShaderExecutableD3D.h" |
Jamie Madill | 437d266 | 2014-12-05 14:23:35 -0500 | [diff] [blame] | 21 | #include "libANGLE/renderer/d3d/VertexDataManager.h" |
Geoff Lang | 2207213 | 2014-11-20 15:15:01 -0500 | [diff] [blame] | 22 | |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 23 | namespace rx |
| 24 | { |
| 25 | |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 26 | namespace |
| 27 | { |
| 28 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 29 | GLenum GetTextureType(GLenum samplerType) |
| 30 | { |
| 31 | switch (samplerType) |
| 32 | { |
| 33 | case GL_SAMPLER_2D: |
| 34 | case GL_INT_SAMPLER_2D: |
| 35 | case GL_UNSIGNED_INT_SAMPLER_2D: |
| 36 | case GL_SAMPLER_2D_SHADOW: |
| 37 | return GL_TEXTURE_2D; |
| 38 | case GL_SAMPLER_3D: |
| 39 | case GL_INT_SAMPLER_3D: |
| 40 | case GL_UNSIGNED_INT_SAMPLER_3D: |
| 41 | return GL_TEXTURE_3D; |
| 42 | case GL_SAMPLER_CUBE: |
| 43 | case GL_SAMPLER_CUBE_SHADOW: |
| 44 | return GL_TEXTURE_CUBE_MAP; |
| 45 | case GL_INT_SAMPLER_CUBE: |
| 46 | case GL_UNSIGNED_INT_SAMPLER_CUBE: |
| 47 | return GL_TEXTURE_CUBE_MAP; |
| 48 | case GL_SAMPLER_2D_ARRAY: |
| 49 | case GL_INT_SAMPLER_2D_ARRAY: |
| 50 | case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: |
| 51 | case GL_SAMPLER_2D_ARRAY_SHADOW: |
| 52 | return GL_TEXTURE_2D_ARRAY; |
| 53 | default: UNREACHABLE(); |
| 54 | } |
| 55 | |
| 56 | return GL_TEXTURE_2D; |
| 57 | } |
| 58 | |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 59 | void GetDefaultInputLayoutFromShader(const std::vector<sh::Attribute> &shaderAttributes, gl::VertexFormat inputLayout[gl::MAX_VERTEX_ATTRIBS]) |
| 60 | { |
| 61 | size_t layoutIndex = 0; |
| 62 | for (size_t attributeIndex = 0; attributeIndex < shaderAttributes.size(); attributeIndex++) |
| 63 | { |
| 64 | ASSERT(layoutIndex < gl::MAX_VERTEX_ATTRIBS); |
| 65 | |
| 66 | const sh::Attribute &shaderAttr = shaderAttributes[attributeIndex]; |
| 67 | |
| 68 | if (shaderAttr.type != GL_NONE) |
| 69 | { |
| 70 | GLenum transposedType = gl::TransposeMatrixType(shaderAttr.type); |
| 71 | |
| 72 | for (size_t rowIndex = 0; static_cast<int>(rowIndex) < gl::VariableRowCount(transposedType); rowIndex++, layoutIndex++) |
| 73 | { |
| 74 | gl::VertexFormat *defaultFormat = &inputLayout[layoutIndex]; |
| 75 | |
| 76 | defaultFormat->mType = gl::VariableComponentType(transposedType); |
| 77 | defaultFormat->mNormalized = false; |
| 78 | defaultFormat->mPureInteger = (defaultFormat->mType != GL_FLOAT); // note: inputs can not be bool |
| 79 | defaultFormat->mComponents = gl::VariableColumnCount(transposedType); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | std::vector<GLenum> GetDefaultOutputLayoutFromShader(const std::vector<PixelShaderOutputVariable> &shaderOutputVars) |
| 86 | { |
Jamie Madill | b446314 | 2014-12-19 14:56:54 -0500 | [diff] [blame] | 87 | std::vector<GLenum> defaultPixelOutput; |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 88 | |
Jamie Madill | b446314 | 2014-12-19 14:56:54 -0500 | [diff] [blame] | 89 | if (!shaderOutputVars.empty()) |
| 90 | { |
| 91 | defaultPixelOutput.push_back(GL_COLOR_ATTACHMENT0 + shaderOutputVars[0].outputIndex); |
| 92 | } |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 93 | |
| 94 | return defaultPixelOutput; |
| 95 | } |
| 96 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 97 | bool IsRowMajorLayout(const sh::InterfaceBlockField &var) |
| 98 | { |
| 99 | return var.isRowMajorLayout; |
| 100 | } |
| 101 | |
| 102 | bool IsRowMajorLayout(const sh::ShaderVariable &var) |
| 103 | { |
| 104 | return false; |
| 105 | } |
| 106 | |
Jamie Madill | 437d266 | 2014-12-05 14:23:35 -0500 | [diff] [blame] | 107 | struct AttributeSorter |
| 108 | { |
| 109 | AttributeSorter(const ProgramImpl::SemanticIndexArray &semanticIndices) |
Jamie Madill | 80d934b | 2015-02-19 10:16:12 -0500 | [diff] [blame] | 110 | : originalIndices(&semanticIndices) |
Jamie Madill | 437d266 | 2014-12-05 14:23:35 -0500 | [diff] [blame] | 111 | { |
| 112 | } |
| 113 | |
| 114 | bool operator()(int a, int b) |
| 115 | { |
Jamie Madill | 80d934b | 2015-02-19 10:16:12 -0500 | [diff] [blame] | 116 | int indexA = (*originalIndices)[a]; |
| 117 | int indexB = (*originalIndices)[b]; |
| 118 | |
| 119 | if (indexA == -1) return false; |
| 120 | if (indexB == -1) return true; |
| 121 | return (indexA < indexB); |
Jamie Madill | 437d266 | 2014-12-05 14:23:35 -0500 | [diff] [blame] | 122 | } |
| 123 | |
Jamie Madill | 80d934b | 2015-02-19 10:16:12 -0500 | [diff] [blame] | 124 | const ProgramImpl::SemanticIndexArray *originalIndices; |
Jamie Madill | 437d266 | 2014-12-05 14:23:35 -0500 | [diff] [blame] | 125 | }; |
| 126 | |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | ProgramD3D::VertexExecutable::VertexExecutable(const gl::VertexFormat inputLayout[], |
| 130 | const GLenum signature[], |
Geoff Lang | 359ef26 | 2015-01-05 14:42:29 -0500 | [diff] [blame] | 131 | ShaderExecutableD3D *shaderExecutable) |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 132 | : mShaderExecutable(shaderExecutable) |
| 133 | { |
| 134 | for (size_t attributeIndex = 0; attributeIndex < gl::MAX_VERTEX_ATTRIBS; attributeIndex++) |
| 135 | { |
| 136 | mInputs[attributeIndex] = inputLayout[attributeIndex]; |
| 137 | mSignature[attributeIndex] = signature[attributeIndex]; |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | ProgramD3D::VertexExecutable::~VertexExecutable() |
| 142 | { |
| 143 | SafeDelete(mShaderExecutable); |
| 144 | } |
| 145 | |
| 146 | bool ProgramD3D::VertexExecutable::matchesSignature(const GLenum signature[]) const |
| 147 | { |
| 148 | for (size_t attributeIndex = 0; attributeIndex < gl::MAX_VERTEX_ATTRIBS; attributeIndex++) |
| 149 | { |
| 150 | if (mSignature[attributeIndex] != signature[attributeIndex]) |
| 151 | { |
| 152 | return false; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | return true; |
| 157 | } |
| 158 | |
Geoff Lang | 359ef26 | 2015-01-05 14:42:29 -0500 | [diff] [blame] | 159 | ProgramD3D::PixelExecutable::PixelExecutable(const std::vector<GLenum> &outputSignature, ShaderExecutableD3D *shaderExecutable) |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 160 | : mOutputSignature(outputSignature), |
| 161 | mShaderExecutable(shaderExecutable) |
| 162 | { |
| 163 | } |
| 164 | |
| 165 | ProgramD3D::PixelExecutable::~PixelExecutable() |
| 166 | { |
| 167 | SafeDelete(mShaderExecutable); |
| 168 | } |
| 169 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 170 | ProgramD3D::Sampler::Sampler() : active(false), logicalTextureUnit(0), textureType(GL_TEXTURE_2D) |
| 171 | { |
| 172 | } |
| 173 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 174 | unsigned int ProgramD3D::mCurrentSerial = 1; |
| 175 | |
Jamie Madill | 93e13fb | 2014-11-06 15:27:25 -0500 | [diff] [blame] | 176 | ProgramD3D::ProgramD3D(RendererD3D *renderer) |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 177 | : ProgramImpl(), |
| 178 | mRenderer(renderer), |
| 179 | mDynamicHLSL(NULL), |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 180 | mGeometryExecutable(NULL), |
Brandon Jones | 44151a9 | 2014-09-10 11:32:25 -0700 | [diff] [blame] | 181 | mUsesPointSize(false), |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 182 | mVertexUniformStorage(NULL), |
Brandon Jones | 44151a9 | 2014-09-10 11:32:25 -0700 | [diff] [blame] | 183 | mFragmentUniformStorage(NULL), |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 184 | mUsedVertexSamplerRange(0), |
| 185 | mUsedPixelSamplerRange(0), |
| 186 | mDirtySamplerMapping(true), |
Geoff Lang | 7a26a1a | 2015-03-25 12:29:06 -0400 | [diff] [blame] | 187 | mTextureUnitTypesCache(renderer->getRendererCaps().maxCombinedTextureImageUnits), |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 188 | mShaderVersion(100), |
| 189 | mSerial(issueSerial()) |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 190 | { |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 191 | mDynamicHLSL = new DynamicHLSL(renderer); |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | ProgramD3D::~ProgramD3D() |
| 195 | { |
| 196 | reset(); |
| 197 | SafeDelete(mDynamicHLSL); |
| 198 | } |
| 199 | |
Brandon Jones | 44151a9 | 2014-09-10 11:32:25 -0700 | [diff] [blame] | 200 | bool ProgramD3D::usesPointSpriteEmulation() const |
| 201 | { |
| 202 | return mUsesPointSize && mRenderer->getMajorShaderModel() >= 4; |
| 203 | } |
| 204 | |
| 205 | bool ProgramD3D::usesGeometryShader() const |
| 206 | { |
Cooper Partin | e6664f0 | 2015-01-09 16:22:24 -0800 | [diff] [blame] | 207 | return usesPointSpriteEmulation() && !usesInstancedPointSpriteEmulation(); |
| 208 | } |
| 209 | |
| 210 | bool ProgramD3D::usesInstancedPointSpriteEmulation() const |
| 211 | { |
| 212 | return mRenderer->getWorkarounds().useInstancedPointSpriteEmulation; |
Brandon Jones | 44151a9 | 2014-09-10 11:32:25 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 215 | GLint ProgramD3D::getSamplerMapping(gl::SamplerType type, unsigned int samplerIndex, const gl::Caps &caps) const |
| 216 | { |
| 217 | GLint logicalTextureUnit = -1; |
| 218 | |
| 219 | switch (type) |
| 220 | { |
| 221 | case gl::SAMPLER_PIXEL: |
| 222 | ASSERT(samplerIndex < caps.maxTextureImageUnits); |
| 223 | if (samplerIndex < mSamplersPS.size() && mSamplersPS[samplerIndex].active) |
| 224 | { |
| 225 | logicalTextureUnit = mSamplersPS[samplerIndex].logicalTextureUnit; |
| 226 | } |
| 227 | break; |
| 228 | case gl::SAMPLER_VERTEX: |
| 229 | ASSERT(samplerIndex < caps.maxVertexTextureImageUnits); |
| 230 | if (samplerIndex < mSamplersVS.size() && mSamplersVS[samplerIndex].active) |
| 231 | { |
| 232 | logicalTextureUnit = mSamplersVS[samplerIndex].logicalTextureUnit; |
| 233 | } |
| 234 | break; |
| 235 | default: UNREACHABLE(); |
| 236 | } |
| 237 | |
| 238 | if (logicalTextureUnit >= 0 && logicalTextureUnit < static_cast<GLint>(caps.maxCombinedTextureImageUnits)) |
| 239 | { |
| 240 | return logicalTextureUnit; |
| 241 | } |
| 242 | |
| 243 | return -1; |
| 244 | } |
| 245 | |
| 246 | // Returns the texture type for a given Direct3D 9 sampler type and |
| 247 | // index (0-15 for the pixel shader and 0-3 for the vertex shader). |
| 248 | GLenum ProgramD3D::getSamplerTextureType(gl::SamplerType type, unsigned int samplerIndex) const |
| 249 | { |
| 250 | switch (type) |
| 251 | { |
| 252 | case gl::SAMPLER_PIXEL: |
| 253 | ASSERT(samplerIndex < mSamplersPS.size()); |
| 254 | ASSERT(mSamplersPS[samplerIndex].active); |
| 255 | return mSamplersPS[samplerIndex].textureType; |
| 256 | case gl::SAMPLER_VERTEX: |
| 257 | ASSERT(samplerIndex < mSamplersVS.size()); |
| 258 | ASSERT(mSamplersVS[samplerIndex].active); |
| 259 | return mSamplersVS[samplerIndex].textureType; |
| 260 | default: UNREACHABLE(); |
| 261 | } |
| 262 | |
| 263 | return GL_TEXTURE_2D; |
| 264 | } |
| 265 | |
| 266 | GLint ProgramD3D::getUsedSamplerRange(gl::SamplerType type) const |
| 267 | { |
| 268 | switch (type) |
| 269 | { |
| 270 | case gl::SAMPLER_PIXEL: |
| 271 | return mUsedPixelSamplerRange; |
| 272 | case gl::SAMPLER_VERTEX: |
| 273 | return mUsedVertexSamplerRange; |
| 274 | default: |
| 275 | UNREACHABLE(); |
| 276 | return 0; |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | void ProgramD3D::updateSamplerMapping() |
| 281 | { |
| 282 | if (!mDirtySamplerMapping) |
| 283 | { |
| 284 | return; |
| 285 | } |
| 286 | |
| 287 | mDirtySamplerMapping = false; |
| 288 | |
| 289 | // Retrieve sampler uniform values |
| 290 | for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); uniformIndex++) |
| 291 | { |
| 292 | gl::LinkedUniform *targetUniform = mUniforms[uniformIndex]; |
| 293 | |
| 294 | if (targetUniform->dirty) |
| 295 | { |
Geoff Lang | 2ec386b | 2014-12-03 14:44:38 -0500 | [diff] [blame] | 296 | if (gl::IsSamplerType(targetUniform->type)) |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 297 | { |
| 298 | int count = targetUniform->elementCount(); |
| 299 | GLint (*v)[4] = reinterpret_cast<GLint(*)[4]>(targetUniform->data); |
| 300 | |
| 301 | if (targetUniform->isReferencedByFragmentShader()) |
| 302 | { |
| 303 | unsigned int firstIndex = targetUniform->psRegisterIndex; |
| 304 | |
| 305 | for (int i = 0; i < count; i++) |
| 306 | { |
| 307 | unsigned int samplerIndex = firstIndex + i; |
| 308 | |
| 309 | if (samplerIndex < mSamplersPS.size()) |
| 310 | { |
| 311 | ASSERT(mSamplersPS[samplerIndex].active); |
| 312 | mSamplersPS[samplerIndex].logicalTextureUnit = v[i][0]; |
| 313 | } |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | if (targetUniform->isReferencedByVertexShader()) |
| 318 | { |
| 319 | unsigned int firstIndex = targetUniform->vsRegisterIndex; |
| 320 | |
| 321 | for (int i = 0; i < count; i++) |
| 322 | { |
| 323 | unsigned int samplerIndex = firstIndex + i; |
| 324 | |
| 325 | if (samplerIndex < mSamplersVS.size()) |
| 326 | { |
| 327 | ASSERT(mSamplersVS[samplerIndex].active); |
| 328 | mSamplersVS[samplerIndex].logicalTextureUnit = v[i][0]; |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | bool ProgramD3D::validateSamplers(gl::InfoLog *infoLog, const gl::Caps &caps) |
| 338 | { |
Jamie Madill | 1377689 | 2015-04-28 12:39:06 -0400 | [diff] [blame] | 339 | // Skip cache if we're using an infolog, so we get the full error. |
| 340 | // Also skip the cache if the sample mapping has changed, or if we haven't ever validated. |
| 341 | if (!mDirtySamplerMapping && infoLog == nullptr && mCachedValidateSamplersResult.valid()) |
| 342 | { |
| 343 | return mCachedValidateSamplersResult.value(); |
| 344 | } |
| 345 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 346 | // if any two active samplers in a program are of different types, but refer to the same |
| 347 | // texture image unit, and this is the current program, then ValidateProgram will fail, and |
| 348 | // DrawArrays and DrawElements will issue the INVALID_OPERATION error. |
| 349 | updateSamplerMapping(); |
| 350 | |
Geoff Lang | 7a26a1a | 2015-03-25 12:29:06 -0400 | [diff] [blame] | 351 | std::fill(mTextureUnitTypesCache.begin(), mTextureUnitTypesCache.end(), GL_NONE); |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 352 | |
| 353 | for (unsigned int i = 0; i < mUsedPixelSamplerRange; ++i) |
| 354 | { |
| 355 | if (mSamplersPS[i].active) |
| 356 | { |
| 357 | unsigned int unit = mSamplersPS[i].logicalTextureUnit; |
| 358 | |
Geoff Lang | 7a26a1a | 2015-03-25 12:29:06 -0400 | [diff] [blame] | 359 | if (unit >= caps.maxCombinedTextureImageUnits) |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 360 | { |
| 361 | if (infoLog) |
| 362 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 363 | (*infoLog) << "Sampler uniform (" << unit |
| 364 | << ") exceeds GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS (" |
| 365 | << caps.maxCombinedTextureImageUnits << ")"; |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Jamie Madill | 1377689 | 2015-04-28 12:39:06 -0400 | [diff] [blame] | 368 | mCachedValidateSamplersResult = false; |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 369 | return false; |
| 370 | } |
| 371 | |
Geoff Lang | 7a26a1a | 2015-03-25 12:29:06 -0400 | [diff] [blame] | 372 | if (mTextureUnitTypesCache[unit] != GL_NONE) |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 373 | { |
Geoff Lang | 7a26a1a | 2015-03-25 12:29:06 -0400 | [diff] [blame] | 374 | if (mSamplersPS[i].textureType != mTextureUnitTypesCache[unit]) |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 375 | { |
| 376 | if (infoLog) |
| 377 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 378 | (*infoLog) << "Samplers of conflicting types refer to the same texture image unit (" |
| 379 | << unit << ")."; |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Jamie Madill | 1377689 | 2015-04-28 12:39:06 -0400 | [diff] [blame] | 382 | mCachedValidateSamplersResult = false; |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 383 | return false; |
| 384 | } |
| 385 | } |
| 386 | else |
| 387 | { |
Geoff Lang | 7a26a1a | 2015-03-25 12:29:06 -0400 | [diff] [blame] | 388 | mTextureUnitTypesCache[unit] = mSamplersPS[i].textureType; |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 389 | } |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | for (unsigned int i = 0; i < mUsedVertexSamplerRange; ++i) |
| 394 | { |
| 395 | if (mSamplersVS[i].active) |
| 396 | { |
| 397 | unsigned int unit = mSamplersVS[i].logicalTextureUnit; |
| 398 | |
Geoff Lang | 7a26a1a | 2015-03-25 12:29:06 -0400 | [diff] [blame] | 399 | if (unit >= caps.maxCombinedTextureImageUnits) |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 400 | { |
| 401 | if (infoLog) |
| 402 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 403 | (*infoLog) << "Sampler uniform (" << unit |
| 404 | << ") exceeds GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS (" |
| 405 | << caps.maxCombinedTextureImageUnits << ")"; |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 406 | } |
| 407 | |
Jamie Madill | 1377689 | 2015-04-28 12:39:06 -0400 | [diff] [blame] | 408 | mCachedValidateSamplersResult = false; |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 409 | return false; |
| 410 | } |
| 411 | |
Geoff Lang | 7a26a1a | 2015-03-25 12:29:06 -0400 | [diff] [blame] | 412 | if (mTextureUnitTypesCache[unit] != GL_NONE) |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 413 | { |
Geoff Lang | 7a26a1a | 2015-03-25 12:29:06 -0400 | [diff] [blame] | 414 | if (mSamplersVS[i].textureType != mTextureUnitTypesCache[unit]) |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 415 | { |
| 416 | if (infoLog) |
| 417 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 418 | (*infoLog) << "Samplers of conflicting types refer to the same texture image unit (" |
| 419 | << unit << ")."; |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Jamie Madill | 1377689 | 2015-04-28 12:39:06 -0400 | [diff] [blame] | 422 | mCachedValidateSamplersResult = false; |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 423 | return false; |
| 424 | } |
| 425 | } |
| 426 | else |
| 427 | { |
Geoff Lang | 7a26a1a | 2015-03-25 12:29:06 -0400 | [diff] [blame] | 428 | mTextureUnitTypesCache[unit] = mSamplersVS[i].textureType; |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 429 | } |
| 430 | } |
| 431 | } |
| 432 | |
Jamie Madill | 1377689 | 2015-04-28 12:39:06 -0400 | [diff] [blame] | 433 | mCachedValidateSamplersResult = true; |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 434 | return true; |
| 435 | } |
| 436 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 437 | LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream) |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 438 | { |
Austin Kinross | 137b151 | 2015-06-17 16:14:53 -0700 | [diff] [blame^] | 439 | DeviceIdentifier binaryDeviceIdentifier = { 0 }; |
| 440 | stream->readBytes(reinterpret_cast<unsigned char*>(&binaryDeviceIdentifier), sizeof(DeviceIdentifier)); |
| 441 | |
| 442 | DeviceIdentifier identifier = mRenderer->getAdapterIdentifier(); |
| 443 | if (memcmp(&identifier, &binaryDeviceIdentifier, sizeof(DeviceIdentifier)) != 0) |
| 444 | { |
| 445 | infoLog << "Invalid program binary, device configuration has changed."; |
| 446 | return LinkResult(false, gl::Error(GL_NO_ERROR)); |
| 447 | } |
| 448 | |
Jamie Madill | 2db1fbb | 2014-12-03 10:58:55 -0500 | [diff] [blame] | 449 | int compileFlags = stream->readInt<int>(); |
| 450 | if (compileFlags != ANGLE_COMPILE_OPTIMIZATION_LEVEL) |
| 451 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 452 | infoLog << "Mismatched compilation flags."; |
Jamie Madill | 2db1fbb | 2014-12-03 10:58:55 -0500 | [diff] [blame] | 453 | return LinkResult(false, gl::Error(GL_NO_ERROR)); |
| 454 | } |
| 455 | |
Brandon Jones | 44151a9 | 2014-09-10 11:32:25 -0700 | [diff] [blame] | 456 | stream->readInt(&mShaderVersion); |
| 457 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 458 | const unsigned int psSamplerCount = stream->readInt<unsigned int>(); |
| 459 | for (unsigned int i = 0; i < psSamplerCount; ++i) |
| 460 | { |
| 461 | Sampler sampler; |
| 462 | stream->readBool(&sampler.active); |
| 463 | stream->readInt(&sampler.logicalTextureUnit); |
| 464 | stream->readInt(&sampler.textureType); |
| 465 | mSamplersPS.push_back(sampler); |
| 466 | } |
| 467 | const unsigned int vsSamplerCount = stream->readInt<unsigned int>(); |
| 468 | for (unsigned int i = 0; i < vsSamplerCount; ++i) |
| 469 | { |
| 470 | Sampler sampler; |
| 471 | stream->readBool(&sampler.active); |
| 472 | stream->readInt(&sampler.logicalTextureUnit); |
| 473 | stream->readInt(&sampler.textureType); |
| 474 | mSamplersVS.push_back(sampler); |
| 475 | } |
| 476 | |
| 477 | stream->readInt(&mUsedVertexSamplerRange); |
| 478 | stream->readInt(&mUsedPixelSamplerRange); |
| 479 | |
| 480 | const unsigned int uniformCount = stream->readInt<unsigned int>(); |
| 481 | if (stream->error()) |
| 482 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 483 | infoLog << "Invalid program binary."; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 484 | return LinkResult(false, gl::Error(GL_NO_ERROR)); |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | mUniforms.resize(uniformCount); |
| 488 | for (unsigned int uniformIndex = 0; uniformIndex < uniformCount; uniformIndex++) |
| 489 | { |
| 490 | GLenum type = stream->readInt<GLenum>(); |
| 491 | GLenum precision = stream->readInt<GLenum>(); |
| 492 | std::string name = stream->readString(); |
| 493 | unsigned int arraySize = stream->readInt<unsigned int>(); |
| 494 | int blockIndex = stream->readInt<int>(); |
| 495 | |
| 496 | int offset = stream->readInt<int>(); |
| 497 | int arrayStride = stream->readInt<int>(); |
| 498 | int matrixStride = stream->readInt<int>(); |
| 499 | bool isRowMajorMatrix = stream->readBool(); |
| 500 | |
| 501 | const sh::BlockMemberInfo blockInfo(offset, arrayStride, matrixStride, isRowMajorMatrix); |
| 502 | |
| 503 | gl::LinkedUniform *uniform = new gl::LinkedUniform(type, precision, name, arraySize, blockIndex, blockInfo); |
| 504 | |
| 505 | stream->readInt(&uniform->psRegisterIndex); |
| 506 | stream->readInt(&uniform->vsRegisterIndex); |
| 507 | stream->readInt(&uniform->registerCount); |
| 508 | stream->readInt(&uniform->registerElement); |
| 509 | |
| 510 | mUniforms[uniformIndex] = uniform; |
| 511 | } |
| 512 | |
| 513 | const unsigned int uniformIndexCount = stream->readInt<unsigned int>(); |
| 514 | if (stream->error()) |
| 515 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 516 | infoLog << "Invalid program binary."; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 517 | return LinkResult(false, gl::Error(GL_NO_ERROR)); |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | mUniformIndex.resize(uniformIndexCount); |
| 521 | for (unsigned int uniformIndexIndex = 0; uniformIndexIndex < uniformIndexCount; uniformIndexIndex++) |
| 522 | { |
| 523 | stream->readString(&mUniformIndex[uniformIndexIndex].name); |
| 524 | stream->readInt(&mUniformIndex[uniformIndexIndex].element); |
| 525 | stream->readInt(&mUniformIndex[uniformIndexIndex].index); |
| 526 | } |
| 527 | |
| 528 | unsigned int uniformBlockCount = stream->readInt<unsigned int>(); |
| 529 | if (stream->error()) |
| 530 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 531 | infoLog << "Invalid program binary."; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 532 | return LinkResult(false, gl::Error(GL_NO_ERROR)); |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | mUniformBlocks.resize(uniformBlockCount); |
| 536 | for (unsigned int uniformBlockIndex = 0; uniformBlockIndex < uniformBlockCount; ++uniformBlockIndex) |
| 537 | { |
| 538 | std::string name = stream->readString(); |
| 539 | unsigned int elementIndex = stream->readInt<unsigned int>(); |
| 540 | unsigned int dataSize = stream->readInt<unsigned int>(); |
| 541 | |
| 542 | gl::UniformBlock *uniformBlock = new gl::UniformBlock(name, elementIndex, dataSize); |
| 543 | |
| 544 | stream->readInt(&uniformBlock->psRegisterIndex); |
| 545 | stream->readInt(&uniformBlock->vsRegisterIndex); |
| 546 | |
| 547 | unsigned int numMembers = stream->readInt<unsigned int>(); |
| 548 | uniformBlock->memberUniformIndexes.resize(numMembers); |
| 549 | for (unsigned int blockMemberIndex = 0; blockMemberIndex < numMembers; blockMemberIndex++) |
| 550 | { |
| 551 | stream->readInt(&uniformBlock->memberUniformIndexes[blockMemberIndex]); |
| 552 | } |
| 553 | |
| 554 | mUniformBlocks[uniformBlockIndex] = uniformBlock; |
| 555 | } |
| 556 | |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 557 | stream->readInt(&mTransformFeedbackBufferMode); |
| 558 | const unsigned int transformFeedbackVaryingCount = stream->readInt<unsigned int>(); |
| 559 | mTransformFeedbackLinkedVaryings.resize(transformFeedbackVaryingCount); |
| 560 | for (unsigned int varyingIndex = 0; varyingIndex < transformFeedbackVaryingCount; varyingIndex++) |
| 561 | { |
| 562 | gl::LinkedVarying &varying = mTransformFeedbackLinkedVaryings[varyingIndex]; |
| 563 | |
| 564 | stream->readString(&varying.name); |
| 565 | stream->readInt(&varying.type); |
| 566 | stream->readInt(&varying.size); |
| 567 | stream->readString(&varying.semanticName); |
| 568 | stream->readInt(&varying.semanticIndex); |
| 569 | stream->readInt(&varying.semanticIndexCount); |
| 570 | } |
| 571 | |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 572 | stream->readString(&mVertexHLSL); |
Arun Patole | 44efa0b | 2015-03-04 17:11:05 +0530 | [diff] [blame] | 573 | stream->readBytes(reinterpret_cast<unsigned char*>(&mVertexWorkarounds), sizeof(D3DCompilerWorkarounds)); |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 574 | stream->readString(&mPixelHLSL); |
Arun Patole | 44efa0b | 2015-03-04 17:11:05 +0530 | [diff] [blame] | 575 | stream->readBytes(reinterpret_cast<unsigned char*>(&mPixelWorkarounds), sizeof(D3DCompilerWorkarounds)); |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 576 | stream->readBool(&mUsesFragDepth); |
Brandon Jones | 44151a9 | 2014-09-10 11:32:25 -0700 | [diff] [blame] | 577 | stream->readBool(&mUsesPointSize); |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 578 | |
| 579 | const size_t pixelShaderKeySize = stream->readInt<unsigned int>(); |
| 580 | mPixelShaderKey.resize(pixelShaderKeySize); |
| 581 | for (size_t pixelShaderKeyIndex = 0; pixelShaderKeyIndex < pixelShaderKeySize; pixelShaderKeyIndex++) |
| 582 | { |
| 583 | stream->readInt(&mPixelShaderKey[pixelShaderKeyIndex].type); |
| 584 | stream->readString(&mPixelShaderKey[pixelShaderKeyIndex].name); |
| 585 | stream->readString(&mPixelShaderKey[pixelShaderKeyIndex].source); |
| 586 | stream->readInt(&mPixelShaderKey[pixelShaderKeyIndex].outputIndex); |
| 587 | } |
| 588 | |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 589 | const unsigned char* binary = reinterpret_cast<const unsigned char*>(stream->data()); |
| 590 | |
| 591 | const unsigned int vertexShaderCount = stream->readInt<unsigned int>(); |
| 592 | for (unsigned int vertexShaderIndex = 0; vertexShaderIndex < vertexShaderCount; vertexShaderIndex++) |
| 593 | { |
| 594 | gl::VertexFormat inputLayout[gl::MAX_VERTEX_ATTRIBS]; |
| 595 | |
| 596 | for (size_t inputIndex = 0; inputIndex < gl::MAX_VERTEX_ATTRIBS; inputIndex++) |
| 597 | { |
| 598 | gl::VertexFormat *vertexInput = &inputLayout[inputIndex]; |
| 599 | stream->readInt(&vertexInput->mType); |
| 600 | stream->readInt(&vertexInput->mNormalized); |
| 601 | stream->readInt(&vertexInput->mComponents); |
| 602 | stream->readBool(&vertexInput->mPureInteger); |
| 603 | } |
| 604 | |
| 605 | unsigned int vertexShaderSize = stream->readInt<unsigned int>(); |
| 606 | const unsigned char *vertexShaderFunction = binary + stream->offset(); |
Geoff Lang | b543aff | 2014-09-30 14:52:54 -0400 | [diff] [blame] | 607 | |
Geoff Lang | 359ef26 | 2015-01-05 14:42:29 -0500 | [diff] [blame] | 608 | ShaderExecutableD3D *shaderExecutable = NULL; |
Geoff Lang | b543aff | 2014-09-30 14:52:54 -0400 | [diff] [blame] | 609 | gl::Error error = mRenderer->loadExecutable(vertexShaderFunction, vertexShaderSize, |
| 610 | SHADER_VERTEX, |
| 611 | mTransformFeedbackLinkedVaryings, |
| 612 | (mTransformFeedbackBufferMode == GL_SEPARATE_ATTRIBS), |
| 613 | &shaderExecutable); |
| 614 | if (error.isError()) |
| 615 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 616 | return LinkResult(false, error); |
Geoff Lang | b543aff | 2014-09-30 14:52:54 -0400 | [diff] [blame] | 617 | } |
| 618 | |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 619 | if (!shaderExecutable) |
| 620 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 621 | infoLog << "Could not create vertex shader."; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 622 | return LinkResult(false, gl::Error(GL_NO_ERROR)); |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | // generated converted input layout |
| 626 | GLenum signature[gl::MAX_VERTEX_ATTRIBS]; |
| 627 | getInputLayoutSignature(inputLayout, signature); |
| 628 | |
| 629 | // add new binary |
| 630 | mVertexExecutables.push_back(new VertexExecutable(inputLayout, signature, shaderExecutable)); |
| 631 | |
| 632 | stream->skip(vertexShaderSize); |
| 633 | } |
| 634 | |
| 635 | const size_t pixelShaderCount = stream->readInt<unsigned int>(); |
| 636 | for (size_t pixelShaderIndex = 0; pixelShaderIndex < pixelShaderCount; pixelShaderIndex++) |
| 637 | { |
| 638 | const size_t outputCount = stream->readInt<unsigned int>(); |
| 639 | std::vector<GLenum> outputs(outputCount); |
| 640 | for (size_t outputIndex = 0; outputIndex < outputCount; outputIndex++) |
| 641 | { |
| 642 | stream->readInt(&outputs[outputIndex]); |
| 643 | } |
| 644 | |
| 645 | const size_t pixelShaderSize = stream->readInt<unsigned int>(); |
| 646 | const unsigned char *pixelShaderFunction = binary + stream->offset(); |
Geoff Lang | 359ef26 | 2015-01-05 14:42:29 -0500 | [diff] [blame] | 647 | ShaderExecutableD3D *shaderExecutable = NULL; |
Geoff Lang | b543aff | 2014-09-30 14:52:54 -0400 | [diff] [blame] | 648 | gl::Error error = mRenderer->loadExecutable(pixelShaderFunction, pixelShaderSize, SHADER_PIXEL, |
| 649 | mTransformFeedbackLinkedVaryings, |
| 650 | (mTransformFeedbackBufferMode == GL_SEPARATE_ATTRIBS), |
| 651 | &shaderExecutable); |
| 652 | if (error.isError()) |
| 653 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 654 | return LinkResult(false, error); |
Geoff Lang | b543aff | 2014-09-30 14:52:54 -0400 | [diff] [blame] | 655 | } |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 656 | |
| 657 | if (!shaderExecutable) |
| 658 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 659 | infoLog << "Could not create pixel shader."; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 660 | return LinkResult(false, gl::Error(GL_NO_ERROR)); |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | // add new binary |
| 664 | mPixelExecutables.push_back(new PixelExecutable(outputs, shaderExecutable)); |
| 665 | |
| 666 | stream->skip(pixelShaderSize); |
| 667 | } |
| 668 | |
| 669 | unsigned int geometryShaderSize = stream->readInt<unsigned int>(); |
| 670 | |
| 671 | if (geometryShaderSize > 0) |
| 672 | { |
| 673 | const unsigned char *geometryShaderFunction = binary + stream->offset(); |
Geoff Lang | b543aff | 2014-09-30 14:52:54 -0400 | [diff] [blame] | 674 | gl::Error error = mRenderer->loadExecutable(geometryShaderFunction, geometryShaderSize, SHADER_GEOMETRY, |
| 675 | mTransformFeedbackLinkedVaryings, |
| 676 | (mTransformFeedbackBufferMode == GL_SEPARATE_ATTRIBS), |
| 677 | &mGeometryExecutable); |
| 678 | if (error.isError()) |
| 679 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 680 | return LinkResult(false, error); |
Geoff Lang | b543aff | 2014-09-30 14:52:54 -0400 | [diff] [blame] | 681 | } |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 682 | |
| 683 | if (!mGeometryExecutable) |
| 684 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 685 | infoLog << "Could not create geometry shader."; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 686 | return LinkResult(false, gl::Error(GL_NO_ERROR)); |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 687 | } |
| 688 | stream->skip(geometryShaderSize); |
| 689 | } |
| 690 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 691 | initializeUniformStorage(); |
Jamie Madill | 437d266 | 2014-12-05 14:23:35 -0500 | [diff] [blame] | 692 | initAttributesByLayout(); |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 693 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 694 | return LinkResult(true, gl::Error(GL_NO_ERROR)); |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 695 | } |
| 696 | |
Geoff Lang | b543aff | 2014-09-30 14:52:54 -0400 | [diff] [blame] | 697 | gl::Error ProgramD3D::save(gl::BinaryOutputStream *stream) |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 698 | { |
Austin Kinross | 137b151 | 2015-06-17 16:14:53 -0700 | [diff] [blame^] | 699 | // Output the DeviceIdentifier before we output any shader code |
| 700 | // When we load the binary again later, we can validate the device identifier before trying to compile any HLSL |
| 701 | DeviceIdentifier binaryIdentifier = mRenderer->getAdapterIdentifier(); |
| 702 | stream->writeBytes(reinterpret_cast<unsigned char*>(&binaryIdentifier), sizeof(DeviceIdentifier)); |
| 703 | |
Jamie Madill | 2db1fbb | 2014-12-03 10:58:55 -0500 | [diff] [blame] | 704 | stream->writeInt(ANGLE_COMPILE_OPTIMIZATION_LEVEL); |
| 705 | |
Brandon Jones | 44151a9 | 2014-09-10 11:32:25 -0700 | [diff] [blame] | 706 | stream->writeInt(mShaderVersion); |
| 707 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 708 | stream->writeInt(mSamplersPS.size()); |
| 709 | for (unsigned int i = 0; i < mSamplersPS.size(); ++i) |
| 710 | { |
| 711 | stream->writeInt(mSamplersPS[i].active); |
| 712 | stream->writeInt(mSamplersPS[i].logicalTextureUnit); |
| 713 | stream->writeInt(mSamplersPS[i].textureType); |
| 714 | } |
| 715 | |
| 716 | stream->writeInt(mSamplersVS.size()); |
| 717 | for (unsigned int i = 0; i < mSamplersVS.size(); ++i) |
| 718 | { |
| 719 | stream->writeInt(mSamplersVS[i].active); |
| 720 | stream->writeInt(mSamplersVS[i].logicalTextureUnit); |
| 721 | stream->writeInt(mSamplersVS[i].textureType); |
| 722 | } |
| 723 | |
| 724 | stream->writeInt(mUsedVertexSamplerRange); |
| 725 | stream->writeInt(mUsedPixelSamplerRange); |
| 726 | |
| 727 | stream->writeInt(mUniforms.size()); |
| 728 | for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); ++uniformIndex) |
| 729 | { |
| 730 | const gl::LinkedUniform &uniform = *mUniforms[uniformIndex]; |
| 731 | |
| 732 | stream->writeInt(uniform.type); |
| 733 | stream->writeInt(uniform.precision); |
| 734 | stream->writeString(uniform.name); |
| 735 | stream->writeInt(uniform.arraySize); |
| 736 | stream->writeInt(uniform.blockIndex); |
| 737 | |
| 738 | stream->writeInt(uniform.blockInfo.offset); |
| 739 | stream->writeInt(uniform.blockInfo.arrayStride); |
| 740 | stream->writeInt(uniform.blockInfo.matrixStride); |
| 741 | stream->writeInt(uniform.blockInfo.isRowMajorMatrix); |
| 742 | |
| 743 | stream->writeInt(uniform.psRegisterIndex); |
| 744 | stream->writeInt(uniform.vsRegisterIndex); |
| 745 | stream->writeInt(uniform.registerCount); |
| 746 | stream->writeInt(uniform.registerElement); |
| 747 | } |
| 748 | |
| 749 | stream->writeInt(mUniformIndex.size()); |
| 750 | for (size_t i = 0; i < mUniformIndex.size(); ++i) |
| 751 | { |
| 752 | stream->writeString(mUniformIndex[i].name); |
| 753 | stream->writeInt(mUniformIndex[i].element); |
| 754 | stream->writeInt(mUniformIndex[i].index); |
| 755 | } |
| 756 | |
| 757 | stream->writeInt(mUniformBlocks.size()); |
| 758 | for (size_t uniformBlockIndex = 0; uniformBlockIndex < mUniformBlocks.size(); ++uniformBlockIndex) |
| 759 | { |
| 760 | const gl::UniformBlock& uniformBlock = *mUniformBlocks[uniformBlockIndex]; |
| 761 | |
| 762 | stream->writeString(uniformBlock.name); |
| 763 | stream->writeInt(uniformBlock.elementIndex); |
| 764 | stream->writeInt(uniformBlock.dataSize); |
| 765 | |
| 766 | stream->writeInt(uniformBlock.memberUniformIndexes.size()); |
| 767 | for (unsigned int blockMemberIndex = 0; blockMemberIndex < uniformBlock.memberUniformIndexes.size(); blockMemberIndex++) |
| 768 | { |
| 769 | stream->writeInt(uniformBlock.memberUniformIndexes[blockMemberIndex]); |
| 770 | } |
| 771 | |
| 772 | stream->writeInt(uniformBlock.psRegisterIndex); |
| 773 | stream->writeInt(uniformBlock.vsRegisterIndex); |
| 774 | } |
| 775 | |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 776 | stream->writeInt(mTransformFeedbackBufferMode); |
| 777 | stream->writeInt(mTransformFeedbackLinkedVaryings.size()); |
| 778 | for (size_t i = 0; i < mTransformFeedbackLinkedVaryings.size(); i++) |
| 779 | { |
| 780 | const gl::LinkedVarying &varying = mTransformFeedbackLinkedVaryings[i]; |
| 781 | |
| 782 | stream->writeString(varying.name); |
| 783 | stream->writeInt(varying.type); |
| 784 | stream->writeInt(varying.size); |
| 785 | stream->writeString(varying.semanticName); |
| 786 | stream->writeInt(varying.semanticIndex); |
| 787 | stream->writeInt(varying.semanticIndexCount); |
| 788 | } |
| 789 | |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 790 | stream->writeString(mVertexHLSL); |
Arun Patole | 44efa0b | 2015-03-04 17:11:05 +0530 | [diff] [blame] | 791 | stream->writeBytes(reinterpret_cast<unsigned char*>(&mVertexWorkarounds), sizeof(D3DCompilerWorkarounds)); |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 792 | stream->writeString(mPixelHLSL); |
Arun Patole | 44efa0b | 2015-03-04 17:11:05 +0530 | [diff] [blame] | 793 | stream->writeBytes(reinterpret_cast<unsigned char*>(&mPixelWorkarounds), sizeof(D3DCompilerWorkarounds)); |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 794 | stream->writeInt(mUsesFragDepth); |
Brandon Jones | 44151a9 | 2014-09-10 11:32:25 -0700 | [diff] [blame] | 795 | stream->writeInt(mUsesPointSize); |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 796 | |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 797 | const std::vector<PixelShaderOutputVariable> &pixelShaderKey = mPixelShaderKey; |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 798 | stream->writeInt(pixelShaderKey.size()); |
| 799 | for (size_t pixelShaderKeyIndex = 0; pixelShaderKeyIndex < pixelShaderKey.size(); pixelShaderKeyIndex++) |
| 800 | { |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 801 | const PixelShaderOutputVariable &variable = pixelShaderKey[pixelShaderKeyIndex]; |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 802 | stream->writeInt(variable.type); |
| 803 | stream->writeString(variable.name); |
| 804 | stream->writeString(variable.source); |
| 805 | stream->writeInt(variable.outputIndex); |
| 806 | } |
| 807 | |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 808 | stream->writeInt(mVertexExecutables.size()); |
| 809 | for (size_t vertexExecutableIndex = 0; vertexExecutableIndex < mVertexExecutables.size(); vertexExecutableIndex++) |
| 810 | { |
| 811 | VertexExecutable *vertexExecutable = mVertexExecutables[vertexExecutableIndex]; |
| 812 | |
| 813 | for (size_t inputIndex = 0; inputIndex < gl::MAX_VERTEX_ATTRIBS; inputIndex++) |
| 814 | { |
| 815 | const gl::VertexFormat &vertexInput = vertexExecutable->inputs()[inputIndex]; |
| 816 | stream->writeInt(vertexInput.mType); |
| 817 | stream->writeInt(vertexInput.mNormalized); |
| 818 | stream->writeInt(vertexInput.mComponents); |
| 819 | stream->writeInt(vertexInput.mPureInteger); |
| 820 | } |
| 821 | |
| 822 | size_t vertexShaderSize = vertexExecutable->shaderExecutable()->getLength(); |
| 823 | stream->writeInt(vertexShaderSize); |
| 824 | |
| 825 | const uint8_t *vertexBlob = vertexExecutable->shaderExecutable()->getFunction(); |
| 826 | stream->writeBytes(vertexBlob, vertexShaderSize); |
| 827 | } |
| 828 | |
| 829 | stream->writeInt(mPixelExecutables.size()); |
| 830 | for (size_t pixelExecutableIndex = 0; pixelExecutableIndex < mPixelExecutables.size(); pixelExecutableIndex++) |
| 831 | { |
| 832 | PixelExecutable *pixelExecutable = mPixelExecutables[pixelExecutableIndex]; |
| 833 | |
| 834 | const std::vector<GLenum> outputs = pixelExecutable->outputSignature(); |
| 835 | stream->writeInt(outputs.size()); |
| 836 | for (size_t outputIndex = 0; outputIndex < outputs.size(); outputIndex++) |
| 837 | { |
| 838 | stream->writeInt(outputs[outputIndex]); |
| 839 | } |
| 840 | |
| 841 | size_t pixelShaderSize = pixelExecutable->shaderExecutable()->getLength(); |
| 842 | stream->writeInt(pixelShaderSize); |
| 843 | |
| 844 | const uint8_t *pixelBlob = pixelExecutable->shaderExecutable()->getFunction(); |
| 845 | stream->writeBytes(pixelBlob, pixelShaderSize); |
| 846 | } |
| 847 | |
| 848 | size_t geometryShaderSize = (mGeometryExecutable != NULL) ? mGeometryExecutable->getLength() : 0; |
| 849 | stream->writeInt(geometryShaderSize); |
| 850 | |
| 851 | if (mGeometryExecutable != NULL && geometryShaderSize > 0) |
| 852 | { |
| 853 | const uint8_t *geometryBlob = mGeometryExecutable->getFunction(); |
| 854 | stream->writeBytes(geometryBlob, geometryShaderSize); |
| 855 | } |
| 856 | |
Geoff Lang | b543aff | 2014-09-30 14:52:54 -0400 | [diff] [blame] | 857 | return gl::Error(GL_NO_ERROR); |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 858 | } |
| 859 | |
Geoff Lang | 359ef26 | 2015-01-05 14:42:29 -0500 | [diff] [blame] | 860 | gl::Error ProgramD3D::getPixelExecutableForFramebuffer(const gl::Framebuffer *fbo, ShaderExecutableD3D **outExecutable) |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 861 | { |
Geoff Lang | 7a26a1a | 2015-03-25 12:29:06 -0400 | [diff] [blame] | 862 | mPixelShaderOutputFormatCache.clear(); |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 863 | |
Jamie Madill | 85a1804 | 2015-03-05 15:41:41 -0500 | [diff] [blame] | 864 | const FramebufferD3D *fboD3D = GetImplAs<FramebufferD3D>(fbo); |
| 865 | const gl::AttachmentList &colorbuffers = fboD3D->getColorAttachmentsForRender(mRenderer->getWorkarounds()); |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 866 | |
| 867 | for (size_t colorAttachment = 0; colorAttachment < colorbuffers.size(); ++colorAttachment) |
| 868 | { |
| 869 | const gl::FramebufferAttachment *colorbuffer = colorbuffers[colorAttachment]; |
| 870 | |
| 871 | if (colorbuffer) |
| 872 | { |
Geoff Lang | 7a26a1a | 2015-03-25 12:29:06 -0400 | [diff] [blame] | 873 | mPixelShaderOutputFormatCache.push_back(colorbuffer->getBinding() == GL_BACK ? GL_COLOR_ATTACHMENT0 : colorbuffer->getBinding()); |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 874 | } |
| 875 | else |
| 876 | { |
Geoff Lang | 7a26a1a | 2015-03-25 12:29:06 -0400 | [diff] [blame] | 877 | mPixelShaderOutputFormatCache.push_back(GL_NONE); |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 878 | } |
| 879 | } |
| 880 | |
Geoff Lang | 7a26a1a | 2015-03-25 12:29:06 -0400 | [diff] [blame] | 881 | return getPixelExecutableForOutputLayout(mPixelShaderOutputFormatCache, outExecutable, nullptr); |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 882 | } |
| 883 | |
Jamie Madill | 9739923 | 2014-12-23 12:31:15 -0500 | [diff] [blame] | 884 | gl::Error ProgramD3D::getPixelExecutableForOutputLayout(const std::vector<GLenum> &outputSignature, |
Geoff Lang | 359ef26 | 2015-01-05 14:42:29 -0500 | [diff] [blame] | 885 | ShaderExecutableD3D **outExectuable, |
Jamie Madill | 9739923 | 2014-12-23 12:31:15 -0500 | [diff] [blame] | 886 | gl::InfoLog *infoLog) |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 887 | { |
| 888 | for (size_t executableIndex = 0; executableIndex < mPixelExecutables.size(); executableIndex++) |
| 889 | { |
| 890 | if (mPixelExecutables[executableIndex]->matchesSignature(outputSignature)) |
| 891 | { |
Geoff Lang | b543aff | 2014-09-30 14:52:54 -0400 | [diff] [blame] | 892 | *outExectuable = mPixelExecutables[executableIndex]->shaderExecutable(); |
| 893 | return gl::Error(GL_NO_ERROR); |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 894 | } |
| 895 | } |
| 896 | |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 897 | std::string finalPixelHLSL = mDynamicHLSL->generatePixelShaderForOutputSignature(mPixelHLSL, mPixelShaderKey, mUsesFragDepth, |
| 898 | outputSignature); |
| 899 | |
| 900 | // Generate new pixel executable |
Geoff Lang | 359ef26 | 2015-01-05 14:42:29 -0500 | [diff] [blame] | 901 | ShaderExecutableD3D *pixelExecutable = NULL; |
Jamie Madill | 9739923 | 2014-12-23 12:31:15 -0500 | [diff] [blame] | 902 | |
| 903 | gl::InfoLog tempInfoLog; |
| 904 | gl::InfoLog *currentInfoLog = infoLog ? infoLog : &tempInfoLog; |
| 905 | |
| 906 | gl::Error error = mRenderer->compileToExecutable(*currentInfoLog, finalPixelHLSL, SHADER_PIXEL, |
Geoff Lang | b543aff | 2014-09-30 14:52:54 -0400 | [diff] [blame] | 907 | mTransformFeedbackLinkedVaryings, |
| 908 | (mTransformFeedbackBufferMode == GL_SEPARATE_ATTRIBS), |
| 909 | mPixelWorkarounds, &pixelExecutable); |
| 910 | if (error.isError()) |
| 911 | { |
| 912 | return error; |
| 913 | } |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 914 | |
Jamie Madill | 9739923 | 2014-12-23 12:31:15 -0500 | [diff] [blame] | 915 | if (pixelExecutable) |
| 916 | { |
| 917 | mPixelExecutables.push_back(new PixelExecutable(outputSignature, pixelExecutable)); |
| 918 | } |
| 919 | else if (!infoLog) |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 920 | { |
| 921 | std::vector<char> tempCharBuffer(tempInfoLog.getLength() + 3); |
| 922 | tempInfoLog.getLog(tempInfoLog.getLength(), NULL, &tempCharBuffer[0]); |
| 923 | ERR("Error compiling dynamic pixel executable:\n%s\n", &tempCharBuffer[0]); |
| 924 | } |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 925 | |
Geoff Lang | b543aff | 2014-09-30 14:52:54 -0400 | [diff] [blame] | 926 | *outExectuable = pixelExecutable; |
| 927 | return gl::Error(GL_NO_ERROR); |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 928 | } |
| 929 | |
Jamie Madill | 9739923 | 2014-12-23 12:31:15 -0500 | [diff] [blame] | 930 | gl::Error ProgramD3D::getVertexExecutableForInputLayout(const gl::VertexFormat inputLayout[gl::MAX_VERTEX_ATTRIBS], |
Geoff Lang | 359ef26 | 2015-01-05 14:42:29 -0500 | [diff] [blame] | 931 | ShaderExecutableD3D **outExectuable, |
Jamie Madill | 9739923 | 2014-12-23 12:31:15 -0500 | [diff] [blame] | 932 | gl::InfoLog *infoLog) |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 933 | { |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 934 | GLenum signature[gl::MAX_VERTEX_ATTRIBS]; |
| 935 | getInputLayoutSignature(inputLayout, signature); |
| 936 | |
| 937 | for (size_t executableIndex = 0; executableIndex < mVertexExecutables.size(); executableIndex++) |
| 938 | { |
| 939 | if (mVertexExecutables[executableIndex]->matchesSignature(signature)) |
| 940 | { |
Geoff Lang | b543aff | 2014-09-30 14:52:54 -0400 | [diff] [blame] | 941 | *outExectuable = mVertexExecutables[executableIndex]->shaderExecutable(); |
| 942 | return gl::Error(GL_NO_ERROR); |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 943 | } |
| 944 | } |
| 945 | |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 946 | // Generate new dynamic layout with attribute conversions |
Jamie Madill | 3da79b7 | 2015-04-27 11:09:17 -0400 | [diff] [blame] | 947 | std::string finalVertexHLSL = mDynamicHLSL->generateVertexShaderForInputLayout(mVertexHLSL, inputLayout, getShaderAttributes()); |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 948 | |
| 949 | // Generate new vertex executable |
Geoff Lang | 359ef26 | 2015-01-05 14:42:29 -0500 | [diff] [blame] | 950 | ShaderExecutableD3D *vertexExecutable = NULL; |
Jamie Madill | 9739923 | 2014-12-23 12:31:15 -0500 | [diff] [blame] | 951 | |
| 952 | gl::InfoLog tempInfoLog; |
| 953 | gl::InfoLog *currentInfoLog = infoLog ? infoLog : &tempInfoLog; |
| 954 | |
| 955 | gl::Error error = mRenderer->compileToExecutable(*currentInfoLog, finalVertexHLSL, SHADER_VERTEX, |
Geoff Lang | b543aff | 2014-09-30 14:52:54 -0400 | [diff] [blame] | 956 | mTransformFeedbackLinkedVaryings, |
| 957 | (mTransformFeedbackBufferMode == GL_SEPARATE_ATTRIBS), |
| 958 | mVertexWorkarounds, &vertexExecutable); |
| 959 | if (error.isError()) |
| 960 | { |
| 961 | return error; |
| 962 | } |
| 963 | |
Jamie Madill | 9739923 | 2014-12-23 12:31:15 -0500 | [diff] [blame] | 964 | if (vertexExecutable) |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 965 | { |
| 966 | mVertexExecutables.push_back(new VertexExecutable(inputLayout, signature, vertexExecutable)); |
| 967 | } |
Jamie Madill | 9739923 | 2014-12-23 12:31:15 -0500 | [diff] [blame] | 968 | else if (!infoLog) |
| 969 | { |
| 970 | std::vector<char> tempCharBuffer(tempInfoLog.getLength() + 3); |
| 971 | tempInfoLog.getLog(tempInfoLog.getLength(), NULL, &tempCharBuffer[0]); |
| 972 | ERR("Error compiling dynamic vertex executable:\n%s\n", &tempCharBuffer[0]); |
| 973 | } |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 974 | |
Geoff Lang | b543aff | 2014-09-30 14:52:54 -0400 | [diff] [blame] | 975 | *outExectuable = vertexExecutable; |
| 976 | return gl::Error(GL_NO_ERROR); |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 977 | } |
| 978 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 979 | LinkResult ProgramD3D::compileProgramExecutables(gl::InfoLog &infoLog, gl::Shader *fragmentShader, gl::Shader *vertexShader, |
| 980 | int registers) |
Brandon Jones | 44151a9 | 2014-09-10 11:32:25 -0700 | [diff] [blame] | 981 | { |
Jamie Madill | f4bf381 | 2015-04-01 16:15:32 -0400 | [diff] [blame] | 982 | ShaderD3D *vertexShaderD3D = GetImplAs<ShaderD3D>(vertexShader); |
| 983 | ShaderD3D *fragmentShaderD3D = GetImplAs<ShaderD3D>(fragmentShader); |
Brandon Jones | 44151a9 | 2014-09-10 11:32:25 -0700 | [diff] [blame] | 984 | |
Jamie Madill | e4ea202 | 2015-03-26 20:35:05 +0000 | [diff] [blame] | 985 | gl::VertexFormat defaultInputLayout[gl::MAX_VERTEX_ATTRIBS]; |
| 986 | GetDefaultInputLayoutFromShader(vertexShader->getActiveAttributes(), defaultInputLayout); |
| 987 | ShaderExecutableD3D *defaultVertexExecutable = NULL; |
| 988 | gl::Error error = getVertexExecutableForInputLayout(defaultInputLayout, &defaultVertexExecutable, &infoLog); |
| 989 | if (error.isError()) |
Austin Kinross | 434953e | 2015-02-20 10:49:51 -0800 | [diff] [blame] | 990 | { |
Jamie Madill | e4ea202 | 2015-03-26 20:35:05 +0000 | [diff] [blame] | 991 | return LinkResult(false, error); |
| 992 | } |
Austin Kinross | 434953e | 2015-02-20 10:49:51 -0800 | [diff] [blame] | 993 | |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 994 | std::vector<GLenum> defaultPixelOutput = GetDefaultOutputLayoutFromShader(getPixelShaderKey()); |
Geoff Lang | 359ef26 | 2015-01-05 14:42:29 -0500 | [diff] [blame] | 995 | ShaderExecutableD3D *defaultPixelExecutable = NULL; |
Jamie Madill | e4ea202 | 2015-03-26 20:35:05 +0000 | [diff] [blame] | 996 | error = getPixelExecutableForOutputLayout(defaultPixelOutput, &defaultPixelExecutable, &infoLog); |
Geoff Lang | b543aff | 2014-09-30 14:52:54 -0400 | [diff] [blame] | 997 | if (error.isError()) |
| 998 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 999 | return LinkResult(false, error); |
Geoff Lang | b543aff | 2014-09-30 14:52:54 -0400 | [diff] [blame] | 1000 | } |
Brandon Jones | 44151a9 | 2014-09-10 11:32:25 -0700 | [diff] [blame] | 1001 | |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 1002 | if (usesGeometryShader()) |
| 1003 | { |
| 1004 | std::string geometryHLSL = mDynamicHLSL->generateGeometryShaderHLSL(registers, fragmentShaderD3D, vertexShaderD3D); |
Brandon Jones | 44151a9 | 2014-09-10 11:32:25 -0700 | [diff] [blame] | 1005 | |
Geoff Lang | b543aff | 2014-09-30 14:52:54 -0400 | [diff] [blame] | 1006 | |
| 1007 | error = mRenderer->compileToExecutable(infoLog, geometryHLSL, SHADER_GEOMETRY, mTransformFeedbackLinkedVaryings, |
| 1008 | (mTransformFeedbackBufferMode == GL_SEPARATE_ATTRIBS), |
Arun Patole | 44efa0b | 2015-03-04 17:11:05 +0530 | [diff] [blame] | 1009 | D3DCompilerWorkarounds(), &mGeometryExecutable); |
Geoff Lang | b543aff | 2014-09-30 14:52:54 -0400 | [diff] [blame] | 1010 | if (error.isError()) |
| 1011 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1012 | return LinkResult(false, error); |
Geoff Lang | b543aff | 2014-09-30 14:52:54 -0400 | [diff] [blame] | 1013 | } |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 1014 | } |
| 1015 | |
Brandon Jones | 091540d | 2014-10-29 11:32:04 -0700 | [diff] [blame] | 1016 | #if ANGLE_SHADER_DEBUG_INFO == ANGLE_ENABLED |
Tibor den Ouden | 97049c6 | 2014-10-06 21:39:16 +0200 | [diff] [blame] | 1017 | if (usesGeometryShader() && mGeometryExecutable) |
| 1018 | { |
| 1019 | // Geometry shaders are currently only used internally, so there is no corresponding shader object at the interface level |
| 1020 | // For now the geometry shader debug info is pre-pended to the vertex shader, this is a bit of a clutch |
| 1021 | vertexShaderD3D->appendDebugInfo("// GEOMETRY SHADER BEGIN\n\n"); |
| 1022 | vertexShaderD3D->appendDebugInfo(mGeometryExecutable->getDebugInfo()); |
| 1023 | vertexShaderD3D->appendDebugInfo("\nGEOMETRY SHADER END\n\n\n"); |
| 1024 | } |
| 1025 | |
| 1026 | if (defaultVertexExecutable) |
| 1027 | { |
| 1028 | vertexShaderD3D->appendDebugInfo(defaultVertexExecutable->getDebugInfo()); |
| 1029 | } |
| 1030 | |
| 1031 | if (defaultPixelExecutable) |
| 1032 | { |
| 1033 | fragmentShaderD3D->appendDebugInfo(defaultPixelExecutable->getDebugInfo()); |
| 1034 | } |
| 1035 | #endif |
| 1036 | |
Geoff Lang | b543aff | 2014-09-30 14:52:54 -0400 | [diff] [blame] | 1037 | bool linkSuccess = (defaultVertexExecutable && defaultPixelExecutable && (!usesGeometryShader() || mGeometryExecutable)); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1038 | return LinkResult(linkSuccess, gl::Error(GL_NO_ERROR)); |
Brandon Jones | 18bd410 | 2014-09-22 14:21:44 -0700 | [diff] [blame] | 1039 | } |
| 1040 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1041 | LinkResult ProgramD3D::link(const gl::Data &data, gl::InfoLog &infoLog, |
| 1042 | gl::Shader *fragmentShader, gl::Shader *vertexShader, |
| 1043 | const std::vector<std::string> &transformFeedbackVaryings, |
| 1044 | GLenum transformFeedbackBufferMode, |
| 1045 | int *registers, std::vector<gl::LinkedVarying> *linkedVaryings, |
| 1046 | std::map<int, gl::VariableLocation> *outputVariables) |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 1047 | { |
Jamie Madill | f4bf381 | 2015-04-01 16:15:32 -0400 | [diff] [blame] | 1048 | ShaderD3D *vertexShaderD3D = GetImplAs<ShaderD3D>(vertexShader); |
| 1049 | ShaderD3D *fragmentShaderD3D = GetImplAs<ShaderD3D>(fragmentShader); |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 1050 | |
Jamie Madill | de8892b | 2014-11-11 13:00:22 -0500 | [diff] [blame] | 1051 | mSamplersPS.resize(data.caps->maxTextureImageUnits); |
| 1052 | mSamplersVS.resize(data.caps->maxVertexTextureImageUnits); |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1053 | |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 1054 | mTransformFeedbackBufferMode = transformFeedbackBufferMode; |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 1055 | |
| 1056 | mPixelHLSL = fragmentShaderD3D->getTranslatedSource(); |
Arun Patole | 44efa0b | 2015-03-04 17:11:05 +0530 | [diff] [blame] | 1057 | fragmentShaderD3D->generateWorkarounds(&mPixelWorkarounds); |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 1058 | |
| 1059 | mVertexHLSL = vertexShaderD3D->getTranslatedSource(); |
Arun Patole | 44efa0b | 2015-03-04 17:11:05 +0530 | [diff] [blame] | 1060 | vertexShaderD3D->generateWorkarounds(&mVertexWorkarounds); |
Brandon Jones | 44151a9 | 2014-09-10 11:32:25 -0700 | [diff] [blame] | 1061 | mShaderVersion = vertexShaderD3D->getShaderVersion(); |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 1062 | |
| 1063 | // Map the varyings to the register file |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 1064 | VaryingPacking packing = { NULL }; |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 1065 | *registers = mDynamicHLSL->packVaryings(infoLog, packing, fragmentShaderD3D, vertexShaderD3D, transformFeedbackVaryings); |
| 1066 | |
Geoff Lang | bdee2d5 | 2014-09-17 11:02:51 -0400 | [diff] [blame] | 1067 | if (*registers < 0) |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 1068 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1069 | return LinkResult(false, gl::Error(GL_NO_ERROR)); |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 1070 | } |
| 1071 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1072 | if (!gl::Program::linkVaryings(infoLog, fragmentShader, vertexShader)) |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 1073 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1074 | return LinkResult(false, gl::Error(GL_NO_ERROR)); |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 1075 | } |
| 1076 | |
Jamie Madill | de8892b | 2014-11-11 13:00:22 -0500 | [diff] [blame] | 1077 | if (!mDynamicHLSL->generateShaderLinkHLSL(data, infoLog, *registers, packing, mPixelHLSL, mVertexHLSL, |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 1078 | fragmentShaderD3D, vertexShaderD3D, transformFeedbackVaryings, |
| 1079 | linkedVaryings, outputVariables, &mPixelShaderKey, &mUsesFragDepth)) |
| 1080 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1081 | return LinkResult(false, gl::Error(GL_NO_ERROR)); |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 1082 | } |
| 1083 | |
Brandon Jones | 44151a9 | 2014-09-10 11:32:25 -0700 | [diff] [blame] | 1084 | mUsesPointSize = vertexShaderD3D->usesPointSize(); |
| 1085 | |
Jamie Madill | 437d266 | 2014-12-05 14:23:35 -0500 | [diff] [blame] | 1086 | initAttributesByLayout(); |
| 1087 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1088 | return LinkResult(true, gl::Error(GL_NO_ERROR)); |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 1089 | } |
| 1090 | |
Geoff Lang | 0ca5378 | 2015-05-07 13:49:39 -0400 | [diff] [blame] | 1091 | void ProgramD3D::bindAttributeLocation(GLuint index, const std::string &name) |
| 1092 | { |
| 1093 | } |
| 1094 | |
Brandon Jones | 44151a9 | 2014-09-10 11:32:25 -0700 | [diff] [blame] | 1095 | void ProgramD3D::getInputLayoutSignature(const gl::VertexFormat inputLayout[], GLenum signature[]) const |
| 1096 | { |
| 1097 | mDynamicHLSL->getInputLayoutSignature(inputLayout, signature); |
| 1098 | } |
| 1099 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1100 | void ProgramD3D::initializeUniformStorage() |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 1101 | { |
| 1102 | // Compute total default block size |
| 1103 | unsigned int vertexRegisters = 0; |
| 1104 | unsigned int fragmentRegisters = 0; |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1105 | for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); uniformIndex++) |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 1106 | { |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1107 | const gl::LinkedUniform &uniform = *mUniforms[uniformIndex]; |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 1108 | |
Geoff Lang | 2ec386b | 2014-12-03 14:44:38 -0500 | [diff] [blame] | 1109 | if (!gl::IsSamplerType(uniform.type)) |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 1110 | { |
| 1111 | if (uniform.isReferencedByVertexShader()) |
| 1112 | { |
| 1113 | vertexRegisters = std::max(vertexRegisters, uniform.vsRegisterIndex + uniform.registerCount); |
| 1114 | } |
| 1115 | if (uniform.isReferencedByFragmentShader()) |
| 1116 | { |
| 1117 | fragmentRegisters = std::max(fragmentRegisters, uniform.psRegisterIndex + uniform.registerCount); |
| 1118 | } |
| 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | mVertexUniformStorage = mRenderer->createUniformStorage(vertexRegisters * 16u); |
| 1123 | mFragmentUniformStorage = mRenderer->createUniformStorage(fragmentRegisters * 16u); |
| 1124 | } |
| 1125 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1126 | gl::Error ProgramD3D::applyUniforms() |
Brandon Jones | 18bd410 | 2014-09-22 14:21:44 -0700 | [diff] [blame] | 1127 | { |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1128 | updateSamplerMapping(); |
| 1129 | |
| 1130 | gl::Error error = mRenderer->applyUniforms(*this, mUniforms); |
| 1131 | if (error.isError()) |
| 1132 | { |
| 1133 | return error; |
| 1134 | } |
| 1135 | |
| 1136 | for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); uniformIndex++) |
| 1137 | { |
| 1138 | mUniforms[uniformIndex]->dirty = false; |
| 1139 | } |
| 1140 | |
| 1141 | return gl::Error(GL_NO_ERROR); |
Brandon Jones | 18bd410 | 2014-09-22 14:21:44 -0700 | [diff] [blame] | 1142 | } |
| 1143 | |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1144 | gl::Error ProgramD3D::applyUniformBuffers(const gl::Data &data, GLuint uniformBlockBindings[]) |
Brandon Jones | 18bd410 | 2014-09-22 14:21:44 -0700 | [diff] [blame] | 1145 | { |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1146 | GLint vertexUniformBuffers[gl::IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS]; |
| 1147 | GLint fragmentUniformBuffers[gl::IMPLEMENTATION_MAX_FRAGMENT_SHADER_UNIFORM_BUFFERS]; |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1148 | |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1149 | for (unsigned int registerIndex = 0; registerIndex < gl::IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS; ++registerIndex) |
| 1150 | { |
| 1151 | vertexUniformBuffers[registerIndex] = -1; |
| 1152 | } |
| 1153 | |
| 1154 | for (unsigned int registerIndex = 0; registerIndex < gl::IMPLEMENTATION_MAX_FRAGMENT_SHADER_UNIFORM_BUFFERS; ++registerIndex) |
| 1155 | { |
| 1156 | fragmentUniformBuffers[registerIndex] = -1; |
| 1157 | } |
Brandon Jones | 18bd410 | 2014-09-22 14:21:44 -0700 | [diff] [blame] | 1158 | |
| 1159 | const unsigned int reservedBuffersInVS = mRenderer->getReservedVertexUniformBuffers(); |
| 1160 | const unsigned int reservedBuffersInFS = mRenderer->getReservedFragmentUniformBuffers(); |
| 1161 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1162 | for (unsigned int uniformBlockIndex = 0; uniformBlockIndex < mUniformBlocks.size(); uniformBlockIndex++) |
Brandon Jones | 18bd410 | 2014-09-22 14:21:44 -0700 | [diff] [blame] | 1163 | { |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1164 | gl::UniformBlock *uniformBlock = mUniformBlocks[uniformBlockIndex]; |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1165 | GLuint blockBinding = uniformBlockBindings[uniformBlockIndex]; |
Brandon Jones | 18bd410 | 2014-09-22 14:21:44 -0700 | [diff] [blame] | 1166 | |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1167 | ASSERT(uniformBlock); |
Brandon Jones | 18bd410 | 2014-09-22 14:21:44 -0700 | [diff] [blame] | 1168 | |
| 1169 | // Unnecessary to apply an unreferenced standard or shared UBO |
| 1170 | if (!uniformBlock->isReferencedByVertexShader() && !uniformBlock->isReferencedByFragmentShader()) |
| 1171 | { |
| 1172 | continue; |
| 1173 | } |
| 1174 | |
| 1175 | if (uniformBlock->isReferencedByVertexShader()) |
| 1176 | { |
| 1177 | unsigned int registerIndex = uniformBlock->vsRegisterIndex - reservedBuffersInVS; |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1178 | ASSERT(vertexUniformBuffers[registerIndex] == -1); |
| 1179 | ASSERT(registerIndex < data.caps->maxVertexUniformBlocks); |
| 1180 | vertexUniformBuffers[registerIndex] = blockBinding; |
Brandon Jones | 18bd410 | 2014-09-22 14:21:44 -0700 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | if (uniformBlock->isReferencedByFragmentShader()) |
| 1184 | { |
| 1185 | unsigned int registerIndex = uniformBlock->psRegisterIndex - reservedBuffersInFS; |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1186 | ASSERT(fragmentUniformBuffers[registerIndex] == -1); |
| 1187 | ASSERT(registerIndex < data.caps->maxFragmentUniformBlocks); |
| 1188 | fragmentUniformBuffers[registerIndex] = blockBinding; |
Brandon Jones | 18bd410 | 2014-09-22 14:21:44 -0700 | [diff] [blame] | 1189 | } |
| 1190 | } |
| 1191 | |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1192 | return mRenderer->setUniformBuffers(data, vertexUniformBuffers, fragmentUniformBuffers); |
Brandon Jones | 18bd410 | 2014-09-22 14:21:44 -0700 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | bool ProgramD3D::assignUniformBlockRegister(gl::InfoLog &infoLog, gl::UniformBlock *uniformBlock, GLenum shader, |
| 1196 | unsigned int registerIndex, const gl::Caps &caps) |
| 1197 | { |
| 1198 | if (shader == GL_VERTEX_SHADER) |
| 1199 | { |
| 1200 | uniformBlock->vsRegisterIndex = registerIndex; |
| 1201 | if (registerIndex - mRenderer->getReservedVertexUniformBuffers() >= caps.maxVertexUniformBlocks) |
| 1202 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 1203 | infoLog << "Vertex shader uniform block count exceed GL_MAX_VERTEX_UNIFORM_BLOCKS (" << caps.maxVertexUniformBlocks << ")"; |
Brandon Jones | 18bd410 | 2014-09-22 14:21:44 -0700 | [diff] [blame] | 1204 | return false; |
| 1205 | } |
| 1206 | } |
| 1207 | else if (shader == GL_FRAGMENT_SHADER) |
| 1208 | { |
| 1209 | uniformBlock->psRegisterIndex = registerIndex; |
| 1210 | if (registerIndex - mRenderer->getReservedFragmentUniformBuffers() >= caps.maxFragmentUniformBlocks) |
| 1211 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 1212 | infoLog << "Fragment shader uniform block count exceed GL_MAX_FRAGMENT_UNIFORM_BLOCKS (" << caps.maxFragmentUniformBlocks << ")"; |
Brandon Jones | 18bd410 | 2014-09-22 14:21:44 -0700 | [diff] [blame] | 1213 | return false; |
| 1214 | } |
| 1215 | } |
| 1216 | else UNREACHABLE(); |
| 1217 | |
| 1218 | return true; |
| 1219 | } |
| 1220 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1221 | void ProgramD3D::dirtyAllUniforms() |
Brandon Jones | 18bd410 | 2014-09-22 14:21:44 -0700 | [diff] [blame] | 1222 | { |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1223 | unsigned int numUniforms = mUniforms.size(); |
| 1224 | for (unsigned int index = 0; index < numUniforms; index++) |
Brandon Jones | 18bd410 | 2014-09-22 14:21:44 -0700 | [diff] [blame] | 1225 | { |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1226 | mUniforms[index]->dirty = true; |
Brandon Jones | 18bd410 | 2014-09-22 14:21:44 -0700 | [diff] [blame] | 1227 | } |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | void ProgramD3D::setUniform1fv(GLint location, GLsizei count, const GLfloat* v) |
| 1231 | { |
| 1232 | setUniform(location, count, v, GL_FLOAT); |
| 1233 | } |
| 1234 | |
| 1235 | void ProgramD3D::setUniform2fv(GLint location, GLsizei count, const GLfloat *v) |
| 1236 | { |
| 1237 | setUniform(location, count, v, GL_FLOAT_VEC2); |
| 1238 | } |
| 1239 | |
| 1240 | void ProgramD3D::setUniform3fv(GLint location, GLsizei count, const GLfloat *v) |
| 1241 | { |
| 1242 | setUniform(location, count, v, GL_FLOAT_VEC3); |
| 1243 | } |
| 1244 | |
| 1245 | void ProgramD3D::setUniform4fv(GLint location, GLsizei count, const GLfloat *v) |
| 1246 | { |
| 1247 | setUniform(location, count, v, GL_FLOAT_VEC4); |
| 1248 | } |
| 1249 | |
| 1250 | void ProgramD3D::setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 1251 | { |
| 1252 | setUniformMatrixfv<2, 2>(location, count, transpose, value, GL_FLOAT_MAT2); |
| 1253 | } |
| 1254 | |
| 1255 | void ProgramD3D::setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 1256 | { |
| 1257 | setUniformMatrixfv<3, 3>(location, count, transpose, value, GL_FLOAT_MAT3); |
| 1258 | } |
| 1259 | |
| 1260 | void ProgramD3D::setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 1261 | { |
| 1262 | setUniformMatrixfv<4, 4>(location, count, transpose, value, GL_FLOAT_MAT4); |
| 1263 | } |
| 1264 | |
| 1265 | void ProgramD3D::setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 1266 | { |
| 1267 | setUniformMatrixfv<2, 3>(location, count, transpose, value, GL_FLOAT_MAT2x3); |
| 1268 | } |
| 1269 | |
| 1270 | void ProgramD3D::setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 1271 | { |
| 1272 | setUniformMatrixfv<3, 2>(location, count, transpose, value, GL_FLOAT_MAT3x2); |
| 1273 | } |
| 1274 | |
| 1275 | void ProgramD3D::setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 1276 | { |
| 1277 | setUniformMatrixfv<2, 4>(location, count, transpose, value, GL_FLOAT_MAT2x4); |
| 1278 | } |
| 1279 | |
| 1280 | void ProgramD3D::setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 1281 | { |
| 1282 | setUniformMatrixfv<4, 2>(location, count, transpose, value, GL_FLOAT_MAT4x2); |
| 1283 | } |
| 1284 | |
| 1285 | void ProgramD3D::setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 1286 | { |
| 1287 | setUniformMatrixfv<3, 4>(location, count, transpose, value, GL_FLOAT_MAT3x4); |
| 1288 | } |
| 1289 | |
| 1290 | void ProgramD3D::setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 1291 | { |
| 1292 | setUniformMatrixfv<4, 3>(location, count, transpose, value, GL_FLOAT_MAT4x3); |
| 1293 | } |
| 1294 | |
| 1295 | void ProgramD3D::setUniform1iv(GLint location, GLsizei count, const GLint *v) |
| 1296 | { |
| 1297 | setUniform(location, count, v, GL_INT); |
| 1298 | } |
| 1299 | |
| 1300 | void ProgramD3D::setUniform2iv(GLint location, GLsizei count, const GLint *v) |
| 1301 | { |
| 1302 | setUniform(location, count, v, GL_INT_VEC2); |
| 1303 | } |
| 1304 | |
| 1305 | void ProgramD3D::setUniform3iv(GLint location, GLsizei count, const GLint *v) |
| 1306 | { |
| 1307 | setUniform(location, count, v, GL_INT_VEC3); |
| 1308 | } |
| 1309 | |
| 1310 | void ProgramD3D::setUniform4iv(GLint location, GLsizei count, const GLint *v) |
| 1311 | { |
| 1312 | setUniform(location, count, v, GL_INT_VEC4); |
| 1313 | } |
| 1314 | |
| 1315 | void ProgramD3D::setUniform1uiv(GLint location, GLsizei count, const GLuint *v) |
| 1316 | { |
| 1317 | setUniform(location, count, v, GL_UNSIGNED_INT); |
| 1318 | } |
| 1319 | |
| 1320 | void ProgramD3D::setUniform2uiv(GLint location, GLsizei count, const GLuint *v) |
| 1321 | { |
| 1322 | setUniform(location, count, v, GL_UNSIGNED_INT_VEC2); |
| 1323 | } |
| 1324 | |
| 1325 | void ProgramD3D::setUniform3uiv(GLint location, GLsizei count, const GLuint *v) |
| 1326 | { |
| 1327 | setUniform(location, count, v, GL_UNSIGNED_INT_VEC3); |
| 1328 | } |
| 1329 | |
| 1330 | void ProgramD3D::setUniform4uiv(GLint location, GLsizei count, const GLuint *v) |
| 1331 | { |
| 1332 | setUniform(location, count, v, GL_UNSIGNED_INT_VEC4); |
| 1333 | } |
| 1334 | |
| 1335 | void ProgramD3D::getUniformfv(GLint location, GLfloat *params) |
| 1336 | { |
| 1337 | getUniformv(location, params, GL_FLOAT); |
| 1338 | } |
| 1339 | |
| 1340 | void ProgramD3D::getUniformiv(GLint location, GLint *params) |
| 1341 | { |
| 1342 | getUniformv(location, params, GL_INT); |
| 1343 | } |
| 1344 | |
| 1345 | void ProgramD3D::getUniformuiv(GLint location, GLuint *params) |
| 1346 | { |
| 1347 | getUniformv(location, params, GL_UNSIGNED_INT); |
| 1348 | } |
| 1349 | |
| 1350 | bool ProgramD3D::linkUniforms(gl::InfoLog &infoLog, const gl::Shader &vertexShader, const gl::Shader &fragmentShader, |
| 1351 | const gl::Caps &caps) |
| 1352 | { |
Jamie Madill | f4bf381 | 2015-04-01 16:15:32 -0400 | [diff] [blame] | 1353 | const ShaderD3D *vertexShaderD3D = GetImplAs<ShaderD3D>(&vertexShader); |
| 1354 | const ShaderD3D *fragmentShaderD3D = GetImplAs<ShaderD3D>(&fragmentShader); |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1355 | |
| 1356 | const std::vector<sh::Uniform> &vertexUniforms = vertexShader.getUniforms(); |
| 1357 | const std::vector<sh::Uniform> &fragmentUniforms = fragmentShader.getUniforms(); |
| 1358 | |
| 1359 | // Check that uniforms defined in the vertex and fragment shaders are identical |
| 1360 | typedef std::map<std::string, const sh::Uniform*> UniformMap; |
| 1361 | UniformMap linkedUniforms; |
| 1362 | |
| 1363 | for (unsigned int vertexUniformIndex = 0; vertexUniformIndex < vertexUniforms.size(); vertexUniformIndex++) |
Brandon Jones | 18bd410 | 2014-09-22 14:21:44 -0700 | [diff] [blame] | 1364 | { |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1365 | const sh::Uniform &vertexUniform = vertexUniforms[vertexUniformIndex]; |
| 1366 | linkedUniforms[vertexUniform.name] = &vertexUniform; |
| 1367 | } |
| 1368 | |
| 1369 | for (unsigned int fragmentUniformIndex = 0; fragmentUniformIndex < fragmentUniforms.size(); fragmentUniformIndex++) |
| 1370 | { |
| 1371 | const sh::Uniform &fragmentUniform = fragmentUniforms[fragmentUniformIndex]; |
| 1372 | UniformMap::const_iterator entry = linkedUniforms.find(fragmentUniform.name); |
| 1373 | if (entry != linkedUniforms.end()) |
| 1374 | { |
| 1375 | const sh::Uniform &vertexUniform = *entry->second; |
| 1376 | const std::string &uniformName = "uniform '" + vertexUniform.name + "'"; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1377 | if (!gl::Program::linkValidateUniforms(infoLog, uniformName, vertexUniform, fragmentUniform)) |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1378 | { |
| 1379 | return false; |
| 1380 | } |
| 1381 | } |
| 1382 | } |
| 1383 | |
| 1384 | for (unsigned int uniformIndex = 0; uniformIndex < vertexUniforms.size(); uniformIndex++) |
| 1385 | { |
| 1386 | const sh::Uniform &uniform = vertexUniforms[uniformIndex]; |
| 1387 | |
| 1388 | if (uniform.staticUse) |
| 1389 | { |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 1390 | unsigned int registerBase = uniform.isBuiltIn() ? GL_INVALID_INDEX : |
| 1391 | vertexShaderD3D->getUniformRegister(uniform.name); |
| 1392 | defineUniformBase(vertexShaderD3D, uniform, registerBase); |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1393 | } |
| 1394 | } |
| 1395 | |
| 1396 | for (unsigned int uniformIndex = 0; uniformIndex < fragmentUniforms.size(); uniformIndex++) |
| 1397 | { |
| 1398 | const sh::Uniform &uniform = fragmentUniforms[uniformIndex]; |
| 1399 | |
| 1400 | if (uniform.staticUse) |
| 1401 | { |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 1402 | unsigned int registerBase = uniform.isBuiltIn() ? GL_INVALID_INDEX : |
| 1403 | fragmentShaderD3D->getUniformRegister(uniform.name); |
| 1404 | defineUniformBase(fragmentShaderD3D, uniform, registerBase); |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1405 | } |
| 1406 | } |
| 1407 | |
| 1408 | if (!indexUniforms(infoLog, caps)) |
| 1409 | { |
| 1410 | return false; |
| 1411 | } |
| 1412 | |
| 1413 | initializeUniformStorage(); |
| 1414 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1415 | return true; |
| 1416 | } |
| 1417 | |
Geoff Lang | 492a7e4 | 2014-11-05 13:27:06 -0500 | [diff] [blame] | 1418 | void ProgramD3D::defineUniformBase(const ShaderD3D *shader, const sh::Uniform &uniform, unsigned int uniformRegister) |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1419 | { |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 1420 | if (uniformRegister == GL_INVALID_INDEX) |
| 1421 | { |
| 1422 | defineUniform(shader, uniform, uniform.name, nullptr); |
| 1423 | return; |
| 1424 | } |
| 1425 | |
Geoff Lang | 492a7e4 | 2014-11-05 13:27:06 -0500 | [diff] [blame] | 1426 | ShShaderOutput outputType = shader->getCompilerOutputType(); |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1427 | sh::HLSLBlockEncoder encoder(sh::HLSLBlockEncoder::GetStrategyFor(outputType)); |
| 1428 | encoder.skipRegisters(uniformRegister); |
| 1429 | |
| 1430 | defineUniform(shader, uniform, uniform.name, &encoder); |
| 1431 | } |
| 1432 | |
Geoff Lang | 492a7e4 | 2014-11-05 13:27:06 -0500 | [diff] [blame] | 1433 | void ProgramD3D::defineUniform(const ShaderD3D *shader, const sh::ShaderVariable &uniform, |
| 1434 | const std::string &fullName, sh::HLSLBlockEncoder *encoder) |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1435 | { |
| 1436 | if (uniform.isStruct()) |
| 1437 | { |
| 1438 | for (unsigned int elementIndex = 0; elementIndex < uniform.elementCount(); elementIndex++) |
| 1439 | { |
| 1440 | const std::string &elementString = (uniform.isArray() ? ArrayString(elementIndex) : ""); |
| 1441 | |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 1442 | if (encoder) |
| 1443 | encoder->enterAggregateType(); |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1444 | |
| 1445 | for (size_t fieldIndex = 0; fieldIndex < uniform.fields.size(); fieldIndex++) |
| 1446 | { |
| 1447 | const sh::ShaderVariable &field = uniform.fields[fieldIndex]; |
| 1448 | const std::string &fieldFullName = (fullName + elementString + "." + field.name); |
| 1449 | |
| 1450 | defineUniform(shader, field, fieldFullName, encoder); |
| 1451 | } |
| 1452 | |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 1453 | if (encoder) |
| 1454 | encoder->exitAggregateType(); |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1455 | } |
| 1456 | } |
| 1457 | else // Not a struct |
| 1458 | { |
| 1459 | // Arrays are treated as aggregate types |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 1460 | if (uniform.isArray() && encoder) |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1461 | { |
| 1462 | encoder->enterAggregateType(); |
| 1463 | } |
| 1464 | |
| 1465 | gl::LinkedUniform *linkedUniform = getUniformByName(fullName); |
| 1466 | |
Jamie Madill | 2857f48 | 2015-02-09 15:35:29 -0500 | [diff] [blame] | 1467 | // Advance the uniform offset, to track registers allocation for structs |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 1468 | sh::BlockMemberInfo blockInfo = encoder ? |
| 1469 | encoder->encodeType(uniform.type, uniform.arraySize, false) : |
| 1470 | sh::BlockMemberInfo::getDefaultBlockInfo(); |
Jamie Madill | 2857f48 | 2015-02-09 15:35:29 -0500 | [diff] [blame] | 1471 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1472 | if (!linkedUniform) |
| 1473 | { |
| 1474 | linkedUniform = new gl::LinkedUniform(uniform.type, uniform.precision, fullName, uniform.arraySize, |
Jamie Madill | 2857f48 | 2015-02-09 15:35:29 -0500 | [diff] [blame] | 1475 | -1, sh::BlockMemberInfo::getDefaultBlockInfo()); |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1476 | ASSERT(linkedUniform); |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 1477 | |
| 1478 | if (encoder) |
| 1479 | linkedUniform->registerElement = sh::HLSLBlockEncoder::getBlockRegisterElement(blockInfo); |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1480 | mUniforms.push_back(linkedUniform); |
| 1481 | } |
| 1482 | |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 1483 | if (encoder) |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1484 | { |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 1485 | if (shader->getShaderType() == GL_FRAGMENT_SHADER) |
| 1486 | { |
| 1487 | linkedUniform->psRegisterIndex = sh::HLSLBlockEncoder::getBlockRegister(blockInfo); |
| 1488 | } |
| 1489 | else if (shader->getShaderType() == GL_VERTEX_SHADER) |
| 1490 | { |
| 1491 | linkedUniform->vsRegisterIndex = sh::HLSLBlockEncoder::getBlockRegister(blockInfo); |
| 1492 | } |
| 1493 | else UNREACHABLE(); |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1494 | } |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1495 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1496 | // Arrays are treated as aggregate types |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 1497 | if (uniform.isArray() && encoder) |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1498 | { |
| 1499 | encoder->exitAggregateType(); |
| 1500 | } |
| 1501 | } |
| 1502 | } |
| 1503 | |
| 1504 | template <typename T> |
| 1505 | static inline void SetIfDirty(T *dest, const T& source, bool *dirtyFlag) |
| 1506 | { |
| 1507 | ASSERT(dest != NULL); |
| 1508 | ASSERT(dirtyFlag != NULL); |
| 1509 | |
| 1510 | *dirtyFlag = *dirtyFlag || (memcmp(dest, &source, sizeof(T)) != 0); |
| 1511 | *dest = source; |
| 1512 | } |
| 1513 | |
| 1514 | template <typename T> |
| 1515 | void ProgramD3D::setUniform(GLint location, GLsizei count, const T* v, GLenum targetUniformType) |
| 1516 | { |
| 1517 | const int components = gl::VariableComponentCount(targetUniformType); |
| 1518 | const GLenum targetBoolType = gl::VariableBoolVectorType(targetUniformType); |
| 1519 | |
| 1520 | gl::LinkedUniform *targetUniform = getUniformByLocation(location); |
| 1521 | |
| 1522 | int elementCount = targetUniform->elementCount(); |
| 1523 | |
| 1524 | count = std::min(elementCount - (int)mUniformIndex[location].element, count); |
| 1525 | |
| 1526 | if (targetUniform->type == targetUniformType) |
| 1527 | { |
| 1528 | T *target = reinterpret_cast<T*>(targetUniform->data) + mUniformIndex[location].element * 4; |
| 1529 | |
| 1530 | for (int i = 0; i < count; i++) |
| 1531 | { |
| 1532 | T *dest = target + (i * 4); |
| 1533 | const T *source = v + (i * components); |
| 1534 | |
| 1535 | for (int c = 0; c < components; c++) |
| 1536 | { |
| 1537 | SetIfDirty(dest + c, source[c], &targetUniform->dirty); |
| 1538 | } |
| 1539 | for (int c = components; c < 4; c++) |
| 1540 | { |
| 1541 | SetIfDirty(dest + c, T(0), &targetUniform->dirty); |
| 1542 | } |
| 1543 | } |
| 1544 | } |
| 1545 | else if (targetUniform->type == targetBoolType) |
| 1546 | { |
| 1547 | GLint *boolParams = reinterpret_cast<GLint*>(targetUniform->data) + mUniformIndex[location].element * 4; |
| 1548 | |
| 1549 | for (int i = 0; i < count; i++) |
| 1550 | { |
| 1551 | GLint *dest = boolParams + (i * 4); |
| 1552 | const T *source = v + (i * components); |
| 1553 | |
| 1554 | for (int c = 0; c < components; c++) |
| 1555 | { |
| 1556 | SetIfDirty(dest + c, (source[c] == static_cast<T>(0)) ? GL_FALSE : GL_TRUE, &targetUniform->dirty); |
| 1557 | } |
| 1558 | for (int c = components; c < 4; c++) |
| 1559 | { |
| 1560 | SetIfDirty(dest + c, GL_FALSE, &targetUniform->dirty); |
| 1561 | } |
| 1562 | } |
| 1563 | } |
Geoff Lang | 2ec386b | 2014-12-03 14:44:38 -0500 | [diff] [blame] | 1564 | else if (gl::IsSamplerType(targetUniform->type)) |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1565 | { |
| 1566 | ASSERT(targetUniformType == GL_INT); |
| 1567 | |
| 1568 | GLint *target = reinterpret_cast<GLint*>(targetUniform->data) + mUniformIndex[location].element * 4; |
| 1569 | |
| 1570 | bool wasDirty = targetUniform->dirty; |
| 1571 | |
| 1572 | for (int i = 0; i < count; i++) |
| 1573 | { |
| 1574 | GLint *dest = target + (i * 4); |
| 1575 | const GLint *source = reinterpret_cast<const GLint*>(v) + (i * components); |
| 1576 | |
| 1577 | SetIfDirty(dest + 0, source[0], &targetUniform->dirty); |
| 1578 | SetIfDirty(dest + 1, 0, &targetUniform->dirty); |
| 1579 | SetIfDirty(dest + 2, 0, &targetUniform->dirty); |
| 1580 | SetIfDirty(dest + 3, 0, &targetUniform->dirty); |
| 1581 | } |
| 1582 | |
| 1583 | if (!wasDirty && targetUniform->dirty) |
| 1584 | { |
| 1585 | mDirtySamplerMapping = true; |
| 1586 | } |
Brandon Jones | 18bd410 | 2014-09-22 14:21:44 -0700 | [diff] [blame] | 1587 | } |
| 1588 | else UNREACHABLE(); |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1589 | } |
Brandon Jones | 18bd410 | 2014-09-22 14:21:44 -0700 | [diff] [blame] | 1590 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1591 | template<typename T> |
| 1592 | bool transposeMatrix(T *target, const GLfloat *value, int targetWidth, int targetHeight, int srcWidth, int srcHeight) |
| 1593 | { |
| 1594 | bool dirty = false; |
| 1595 | int copyWidth = std::min(targetHeight, srcWidth); |
| 1596 | int copyHeight = std::min(targetWidth, srcHeight); |
| 1597 | |
| 1598 | for (int x = 0; x < copyWidth; x++) |
| 1599 | { |
| 1600 | for (int y = 0; y < copyHeight; y++) |
| 1601 | { |
| 1602 | SetIfDirty(target + (x * targetWidth + y), static_cast<T>(value[y * srcWidth + x]), &dirty); |
| 1603 | } |
| 1604 | } |
| 1605 | // clear unfilled right side |
| 1606 | for (int y = 0; y < copyWidth; y++) |
| 1607 | { |
| 1608 | for (int x = copyHeight; x < targetWidth; x++) |
| 1609 | { |
| 1610 | SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty); |
| 1611 | } |
| 1612 | } |
| 1613 | // clear unfilled bottom. |
| 1614 | for (int y = copyWidth; y < targetHeight; y++) |
| 1615 | { |
| 1616 | for (int x = 0; x < targetWidth; x++) |
| 1617 | { |
| 1618 | SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty); |
| 1619 | } |
| 1620 | } |
| 1621 | |
| 1622 | return dirty; |
| 1623 | } |
| 1624 | |
| 1625 | template<typename T> |
| 1626 | bool expandMatrix(T *target, const GLfloat *value, int targetWidth, int targetHeight, int srcWidth, int srcHeight) |
| 1627 | { |
| 1628 | bool dirty = false; |
| 1629 | int copyWidth = std::min(targetWidth, srcWidth); |
| 1630 | int copyHeight = std::min(targetHeight, srcHeight); |
| 1631 | |
| 1632 | for (int y = 0; y < copyHeight; y++) |
| 1633 | { |
| 1634 | for (int x = 0; x < copyWidth; x++) |
| 1635 | { |
| 1636 | SetIfDirty(target + (y * targetWidth + x), static_cast<T>(value[y * srcWidth + x]), &dirty); |
| 1637 | } |
| 1638 | } |
| 1639 | // clear unfilled right side |
| 1640 | for (int y = 0; y < copyHeight; y++) |
| 1641 | { |
| 1642 | for (int x = copyWidth; x < targetWidth; x++) |
| 1643 | { |
| 1644 | SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty); |
| 1645 | } |
| 1646 | } |
| 1647 | // clear unfilled bottom. |
| 1648 | for (int y = copyHeight; y < targetHeight; y++) |
| 1649 | { |
| 1650 | for (int x = 0; x < targetWidth; x++) |
| 1651 | { |
| 1652 | SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty); |
| 1653 | } |
| 1654 | } |
| 1655 | |
| 1656 | return dirty; |
| 1657 | } |
| 1658 | |
| 1659 | template <int cols, int rows> |
| 1660 | void ProgramD3D::setUniformMatrixfv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value, GLenum targetUniformType) |
| 1661 | { |
| 1662 | gl::LinkedUniform *targetUniform = getUniformByLocation(location); |
| 1663 | |
| 1664 | int elementCount = targetUniform->elementCount(); |
| 1665 | |
| 1666 | count = std::min(elementCount - (int)mUniformIndex[location].element, count); |
| 1667 | const unsigned int targetMatrixStride = (4 * rows); |
| 1668 | GLfloat *target = (GLfloat*)(targetUniform->data + mUniformIndex[location].element * sizeof(GLfloat) * targetMatrixStride); |
| 1669 | |
| 1670 | for (int i = 0; i < count; i++) |
| 1671 | { |
| 1672 | // Internally store matrices as transposed versions to accomodate HLSL matrix indexing |
| 1673 | if (transpose == GL_FALSE) |
| 1674 | { |
| 1675 | targetUniform->dirty = transposeMatrix<GLfloat>(target, value, 4, rows, rows, cols) || targetUniform->dirty; |
| 1676 | } |
| 1677 | else |
| 1678 | { |
| 1679 | targetUniform->dirty = expandMatrix<GLfloat>(target, value, 4, rows, cols, rows) || targetUniform->dirty; |
| 1680 | } |
| 1681 | target += targetMatrixStride; |
| 1682 | value += cols * rows; |
| 1683 | } |
| 1684 | } |
| 1685 | |
| 1686 | template <typename T> |
| 1687 | void ProgramD3D::getUniformv(GLint location, T *params, GLenum uniformType) |
| 1688 | { |
| 1689 | gl::LinkedUniform *targetUniform = mUniforms[mUniformIndex[location].index]; |
| 1690 | |
| 1691 | if (gl::IsMatrixType(targetUniform->type)) |
| 1692 | { |
| 1693 | const int rows = gl::VariableRowCount(targetUniform->type); |
| 1694 | const int cols = gl::VariableColumnCount(targetUniform->type); |
| 1695 | transposeMatrix(params, (GLfloat*)targetUniform->data + mUniformIndex[location].element * 4 * rows, rows, cols, 4, rows); |
| 1696 | } |
| 1697 | else if (uniformType == gl::VariableComponentType(targetUniform->type)) |
| 1698 | { |
| 1699 | unsigned int size = gl::VariableComponentCount(targetUniform->type); |
| 1700 | memcpy(params, targetUniform->data + mUniformIndex[location].element * 4 * sizeof(T), |
| 1701 | size * sizeof(T)); |
| 1702 | } |
| 1703 | else |
| 1704 | { |
| 1705 | unsigned int size = gl::VariableComponentCount(targetUniform->type); |
| 1706 | switch (gl::VariableComponentType(targetUniform->type)) |
| 1707 | { |
| 1708 | case GL_BOOL: |
| 1709 | { |
| 1710 | GLint *boolParams = (GLint*)targetUniform->data + mUniformIndex[location].element * 4; |
| 1711 | |
| 1712 | for (unsigned int i = 0; i < size; i++) |
| 1713 | { |
| 1714 | params[i] = (boolParams[i] == GL_FALSE) ? static_cast<T>(0) : static_cast<T>(1); |
| 1715 | } |
| 1716 | } |
| 1717 | break; |
| 1718 | |
| 1719 | case GL_FLOAT: |
| 1720 | { |
| 1721 | GLfloat *floatParams = (GLfloat*)targetUniform->data + mUniformIndex[location].element * 4; |
| 1722 | |
| 1723 | for (unsigned int i = 0; i < size; i++) |
| 1724 | { |
| 1725 | params[i] = static_cast<T>(floatParams[i]); |
| 1726 | } |
| 1727 | } |
| 1728 | break; |
| 1729 | |
| 1730 | case GL_INT: |
| 1731 | { |
| 1732 | GLint *intParams = (GLint*)targetUniform->data + mUniformIndex[location].element * 4; |
| 1733 | |
| 1734 | for (unsigned int i = 0; i < size; i++) |
| 1735 | { |
| 1736 | params[i] = static_cast<T>(intParams[i]); |
| 1737 | } |
| 1738 | } |
| 1739 | break; |
| 1740 | |
| 1741 | case GL_UNSIGNED_INT: |
| 1742 | { |
| 1743 | GLuint *uintParams = (GLuint*)targetUniform->data + mUniformIndex[location].element * 4; |
| 1744 | |
| 1745 | for (unsigned int i = 0; i < size; i++) |
| 1746 | { |
| 1747 | params[i] = static_cast<T>(uintParams[i]); |
| 1748 | } |
| 1749 | } |
| 1750 | break; |
| 1751 | |
| 1752 | default: UNREACHABLE(); |
| 1753 | } |
| 1754 | } |
| 1755 | } |
| 1756 | |
| 1757 | template <typename VarT> |
| 1758 | void ProgramD3D::defineUniformBlockMembers(const std::vector<VarT> &fields, const std::string &prefix, int blockIndex, |
| 1759 | sh::BlockLayoutEncoder *encoder, std::vector<unsigned int> *blockUniformIndexes, |
| 1760 | bool inRowMajorLayout) |
| 1761 | { |
| 1762 | for (unsigned int uniformIndex = 0; uniformIndex < fields.size(); uniformIndex++) |
| 1763 | { |
| 1764 | const VarT &field = fields[uniformIndex]; |
| 1765 | const std::string &fieldName = (prefix.empty() ? field.name : prefix + "." + field.name); |
| 1766 | |
| 1767 | if (field.isStruct()) |
| 1768 | { |
| 1769 | bool rowMajorLayout = (inRowMajorLayout || IsRowMajorLayout(field)); |
| 1770 | |
| 1771 | for (unsigned int arrayElement = 0; arrayElement < field.elementCount(); arrayElement++) |
| 1772 | { |
| 1773 | encoder->enterAggregateType(); |
| 1774 | |
| 1775 | const std::string uniformElementName = fieldName + (field.isArray() ? ArrayString(arrayElement) : ""); |
| 1776 | defineUniformBlockMembers(field.fields, uniformElementName, blockIndex, encoder, blockUniformIndexes, rowMajorLayout); |
| 1777 | |
| 1778 | encoder->exitAggregateType(); |
| 1779 | } |
| 1780 | } |
| 1781 | else |
| 1782 | { |
| 1783 | bool isRowMajorMatrix = (gl::IsMatrixType(field.type) && inRowMajorLayout); |
| 1784 | |
| 1785 | sh::BlockMemberInfo memberInfo = encoder->encodeType(field.type, field.arraySize, isRowMajorMatrix); |
| 1786 | |
| 1787 | gl::LinkedUniform *newUniform = new gl::LinkedUniform(field.type, field.precision, fieldName, field.arraySize, |
| 1788 | blockIndex, memberInfo); |
| 1789 | |
| 1790 | // add to uniform list, but not index, since uniform block uniforms have no location |
| 1791 | blockUniformIndexes->push_back(mUniforms.size()); |
| 1792 | mUniforms.push_back(newUniform); |
| 1793 | } |
| 1794 | } |
| 1795 | } |
| 1796 | |
| 1797 | bool ProgramD3D::defineUniformBlock(gl::InfoLog &infoLog, const gl::Shader &shader, const sh::InterfaceBlock &interfaceBlock, |
| 1798 | const gl::Caps &caps) |
| 1799 | { |
Jamie Madill | f4bf381 | 2015-04-01 16:15:32 -0400 | [diff] [blame] | 1800 | const ShaderD3D* shaderD3D = GetImplAs<ShaderD3D>(&shader); |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1801 | |
| 1802 | // create uniform block entries if they do not exist |
| 1803 | if (getUniformBlockIndex(interfaceBlock.name) == GL_INVALID_INDEX) |
| 1804 | { |
| 1805 | std::vector<unsigned int> blockUniformIndexes; |
| 1806 | const unsigned int blockIndex = mUniformBlocks.size(); |
| 1807 | |
| 1808 | // define member uniforms |
| 1809 | sh::BlockLayoutEncoder *encoder = NULL; |
| 1810 | |
| 1811 | if (interfaceBlock.layout == sh::BLOCKLAYOUT_STANDARD) |
| 1812 | { |
| 1813 | encoder = new sh::Std140BlockEncoder; |
| 1814 | } |
| 1815 | else |
| 1816 | { |
| 1817 | encoder = new sh::HLSLBlockEncoder(sh::HLSLBlockEncoder::ENCODE_PACKED); |
| 1818 | } |
| 1819 | ASSERT(encoder); |
| 1820 | |
| 1821 | defineUniformBlockMembers(interfaceBlock.fields, "", blockIndex, encoder, &blockUniformIndexes, interfaceBlock.isRowMajorLayout); |
| 1822 | |
| 1823 | size_t dataSize = encoder->getBlockSize(); |
| 1824 | |
| 1825 | // create all the uniform blocks |
| 1826 | if (interfaceBlock.arraySize > 0) |
| 1827 | { |
| 1828 | for (unsigned int uniformBlockElement = 0; uniformBlockElement < interfaceBlock.arraySize; uniformBlockElement++) |
| 1829 | { |
| 1830 | gl::UniformBlock *newUniformBlock = new gl::UniformBlock(interfaceBlock.name, uniformBlockElement, dataSize); |
| 1831 | newUniformBlock->memberUniformIndexes = blockUniformIndexes; |
| 1832 | mUniformBlocks.push_back(newUniformBlock); |
| 1833 | } |
| 1834 | } |
| 1835 | else |
| 1836 | { |
| 1837 | gl::UniformBlock *newUniformBlock = new gl::UniformBlock(interfaceBlock.name, GL_INVALID_INDEX, dataSize); |
| 1838 | newUniformBlock->memberUniformIndexes = blockUniformIndexes; |
| 1839 | mUniformBlocks.push_back(newUniformBlock); |
| 1840 | } |
| 1841 | } |
| 1842 | |
| 1843 | if (interfaceBlock.staticUse) |
| 1844 | { |
| 1845 | // Assign registers to the uniform blocks |
| 1846 | const GLuint blockIndex = getUniformBlockIndex(interfaceBlock.name); |
| 1847 | const unsigned int elementCount = std::max(1u, interfaceBlock.arraySize); |
| 1848 | ASSERT(blockIndex != GL_INVALID_INDEX); |
| 1849 | ASSERT(blockIndex + elementCount <= mUniformBlocks.size()); |
| 1850 | |
| 1851 | unsigned int interfaceBlockRegister = shaderD3D->getInterfaceBlockRegister(interfaceBlock.name); |
| 1852 | |
| 1853 | for (unsigned int uniformBlockElement = 0; uniformBlockElement < elementCount; uniformBlockElement++) |
| 1854 | { |
| 1855 | gl::UniformBlock *uniformBlock = mUniformBlocks[blockIndex + uniformBlockElement]; |
| 1856 | ASSERT(uniformBlock->name == interfaceBlock.name); |
| 1857 | |
| 1858 | if (!assignUniformBlockRegister(infoLog, uniformBlock, shader.getType(), |
| 1859 | interfaceBlockRegister + uniformBlockElement, caps)) |
| 1860 | { |
| 1861 | return false; |
| 1862 | } |
| 1863 | } |
| 1864 | } |
| 1865 | |
| 1866 | return true; |
| 1867 | } |
| 1868 | |
| 1869 | bool ProgramD3D::assignSamplers(unsigned int startSamplerIndex, |
| 1870 | GLenum samplerType, |
| 1871 | unsigned int samplerCount, |
| 1872 | std::vector<Sampler> &outSamplers, |
| 1873 | GLuint *outUsedRange) |
| 1874 | { |
| 1875 | unsigned int samplerIndex = startSamplerIndex; |
| 1876 | |
| 1877 | do |
| 1878 | { |
| 1879 | if (samplerIndex < outSamplers.size()) |
| 1880 | { |
| 1881 | Sampler& sampler = outSamplers[samplerIndex]; |
| 1882 | sampler.active = true; |
| 1883 | sampler.textureType = GetTextureType(samplerType); |
| 1884 | sampler.logicalTextureUnit = 0; |
| 1885 | *outUsedRange = std::max(samplerIndex + 1, *outUsedRange); |
| 1886 | } |
| 1887 | else |
| 1888 | { |
| 1889 | return false; |
| 1890 | } |
| 1891 | |
| 1892 | samplerIndex++; |
| 1893 | } while (samplerIndex < startSamplerIndex + samplerCount); |
| 1894 | |
| 1895 | return true; |
| 1896 | } |
| 1897 | |
| 1898 | bool ProgramD3D::indexSamplerUniform(const gl::LinkedUniform &uniform, gl::InfoLog &infoLog, const gl::Caps &caps) |
| 1899 | { |
Geoff Lang | 2ec386b | 2014-12-03 14:44:38 -0500 | [diff] [blame] | 1900 | ASSERT(gl::IsSamplerType(uniform.type)); |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1901 | ASSERT(uniform.vsRegisterIndex != GL_INVALID_INDEX || uniform.psRegisterIndex != GL_INVALID_INDEX); |
| 1902 | |
| 1903 | if (uniform.vsRegisterIndex != GL_INVALID_INDEX) |
| 1904 | { |
| 1905 | if (!assignSamplers(uniform.vsRegisterIndex, uniform.type, uniform.arraySize, mSamplersVS, |
| 1906 | &mUsedVertexSamplerRange)) |
| 1907 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 1908 | infoLog << "Vertex shader sampler count exceeds the maximum vertex texture units (" |
| 1909 | << mSamplersVS.size() << ")."; |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1910 | return false; |
| 1911 | } |
| 1912 | |
| 1913 | unsigned int maxVertexVectors = mRenderer->getReservedVertexUniformVectors() + caps.maxVertexUniformVectors; |
| 1914 | if (uniform.vsRegisterIndex + uniform.registerCount > maxVertexVectors) |
| 1915 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 1916 | infoLog << "Vertex shader active uniforms exceed GL_MAX_VERTEX_UNIFORM_VECTORS (" |
| 1917 | << caps.maxVertexUniformVectors << ")."; |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1918 | return false; |
| 1919 | } |
| 1920 | } |
| 1921 | |
| 1922 | if (uniform.psRegisterIndex != GL_INVALID_INDEX) |
| 1923 | { |
| 1924 | if (!assignSamplers(uniform.psRegisterIndex, uniform.type, uniform.arraySize, mSamplersPS, |
| 1925 | &mUsedPixelSamplerRange)) |
| 1926 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 1927 | infoLog << "Pixel shader sampler count exceeds MAX_TEXTURE_IMAGE_UNITS (" |
| 1928 | << mSamplersPS.size() << ")."; |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1929 | return false; |
| 1930 | } |
| 1931 | |
| 1932 | unsigned int maxFragmentVectors = mRenderer->getReservedFragmentUniformVectors() + caps.maxFragmentUniformVectors; |
| 1933 | if (uniform.psRegisterIndex + uniform.registerCount > maxFragmentVectors) |
| 1934 | { |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 1935 | infoLog << "Fragment shader active uniforms exceed GL_MAX_FRAGMENT_UNIFORM_VECTORS (" |
| 1936 | << caps.maxFragmentUniformVectors << ")."; |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1937 | return false; |
| 1938 | } |
| 1939 | } |
| 1940 | |
| 1941 | return true; |
| 1942 | } |
| 1943 | |
| 1944 | bool ProgramD3D::indexUniforms(gl::InfoLog &infoLog, const gl::Caps &caps) |
| 1945 | { |
| 1946 | for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); uniformIndex++) |
| 1947 | { |
| 1948 | const gl::LinkedUniform &uniform = *mUniforms[uniformIndex]; |
| 1949 | |
Geoff Lang | 2ec386b | 2014-12-03 14:44:38 -0500 | [diff] [blame] | 1950 | if (gl::IsSamplerType(uniform.type)) |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1951 | { |
| 1952 | if (!indexSamplerUniform(uniform, infoLog, caps)) |
| 1953 | { |
| 1954 | return false; |
| 1955 | } |
| 1956 | } |
| 1957 | |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 1958 | for (unsigned int arrayIndex = 0; arrayIndex < uniform.elementCount(); arrayIndex++) |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1959 | { |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 1960 | if (!uniform.isBuiltIn()) |
| 1961 | { |
| 1962 | mUniformIndex.push_back(gl::VariableLocation(uniform.name, arrayIndex, uniformIndex)); |
| 1963 | } |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1964 | } |
| 1965 | } |
| 1966 | |
| 1967 | return true; |
Brandon Jones | 18bd410 | 2014-09-22 14:21:44 -0700 | [diff] [blame] | 1968 | } |
| 1969 | |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 1970 | void ProgramD3D::reset() |
| 1971 | { |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1972 | ProgramImpl::reset(); |
| 1973 | |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 1974 | SafeDeleteContainer(mVertexExecutables); |
| 1975 | SafeDeleteContainer(mPixelExecutables); |
| 1976 | SafeDelete(mGeometryExecutable); |
| 1977 | |
| 1978 | mTransformFeedbackBufferMode = GL_NONE; |
Brandon Jones | eb99436 | 2014-09-24 10:27:28 -0700 | [diff] [blame] | 1979 | |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 1980 | mVertexHLSL.clear(); |
Arun Patole | 44efa0b | 2015-03-04 17:11:05 +0530 | [diff] [blame] | 1981 | mVertexWorkarounds.reset(); |
Brandon Jones | 44151a9 | 2014-09-10 11:32:25 -0700 | [diff] [blame] | 1982 | mShaderVersion = 100; |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 1983 | |
| 1984 | mPixelHLSL.clear(); |
Arun Patole | 44efa0b | 2015-03-04 17:11:05 +0530 | [diff] [blame] | 1985 | mPixelWorkarounds.reset(); |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 1986 | mUsesFragDepth = false; |
| 1987 | mPixelShaderKey.clear(); |
Brandon Jones | 44151a9 | 2014-09-10 11:32:25 -0700 | [diff] [blame] | 1988 | mUsesPointSize = false; |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 1989 | |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 1990 | SafeDelete(mVertexUniformStorage); |
| 1991 | SafeDelete(mFragmentUniformStorage); |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 1992 | |
| 1993 | mSamplersPS.clear(); |
| 1994 | mSamplersVS.clear(); |
| 1995 | |
| 1996 | mUsedVertexSamplerRange = 0; |
| 1997 | mUsedPixelSamplerRange = 0; |
| 1998 | mDirtySamplerMapping = true; |
Jamie Madill | 437d266 | 2014-12-05 14:23:35 -0500 | [diff] [blame] | 1999 | |
| 2000 | std::fill(mAttributesByLayout, mAttributesByLayout + ArraySize(mAttributesByLayout), -1); |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 2001 | } |
| 2002 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2003 | unsigned int ProgramD3D::getSerial() const |
| 2004 | { |
| 2005 | return mSerial; |
| 2006 | } |
| 2007 | |
| 2008 | unsigned int ProgramD3D::issueSerial() |
| 2009 | { |
| 2010 | return mCurrentSerial++; |
| 2011 | } |
| 2012 | |
Jamie Madill | 437d266 | 2014-12-05 14:23:35 -0500 | [diff] [blame] | 2013 | void ProgramD3D::initAttributesByLayout() |
| 2014 | { |
| 2015 | for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
| 2016 | { |
| 2017 | mAttributesByLayout[i] = i; |
| 2018 | } |
| 2019 | |
| 2020 | std::sort(&mAttributesByLayout[0], &mAttributesByLayout[gl::MAX_VERTEX_ATTRIBS], AttributeSorter(mSemanticIndex)); |
| 2021 | } |
| 2022 | |
Jamie Madill | 476682e | 2015-06-30 10:04:29 -0400 | [diff] [blame] | 2023 | void ProgramD3D::sortAttributesByLayout(const std::vector<TranslatedAttribute> &unsortedAttributes, |
Jamie Madill | f9327d3 | 2015-06-22 13:57:16 -0400 | [diff] [blame] | 2024 | int sortedSemanticIndicesOut[gl::MAX_VERTEX_ATTRIBS], |
| 2025 | const rx::TranslatedAttribute *sortedAttributesOut[gl::MAX_VERTEX_ATTRIBS]) const |
Jamie Madill | 437d266 | 2014-12-05 14:23:35 -0500 | [diff] [blame] | 2026 | { |
Jamie Madill | 476682e | 2015-06-30 10:04:29 -0400 | [diff] [blame] | 2027 | for (size_t attribIndex = 0; attribIndex < unsortedAttributes.size(); ++attribIndex) |
Jamie Madill | 437d266 | 2014-12-05 14:23:35 -0500 | [diff] [blame] | 2028 | { |
Jamie Madill | 476682e | 2015-06-30 10:04:29 -0400 | [diff] [blame] | 2029 | int oldIndex = mAttributesByLayout[attribIndex]; |
| 2030 | sortedSemanticIndicesOut[attribIndex] = mSemanticIndex[oldIndex]; |
| 2031 | sortedAttributesOut[attribIndex] = &unsortedAttributes[oldIndex]; |
Jamie Madill | 437d266 | 2014-12-05 14:23:35 -0500 | [diff] [blame] | 2032 | } |
| 2033 | } |
| 2034 | |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 2035 | } |