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 | |
| 9 | #include "libGLESv2/renderer/d3d/ProgramD3D.h" |
| 10 | |
| 11 | #include "common/utilities.h" |
| 12 | #include "libGLESv2/ProgramBinary.h" |
| 13 | #include "libGLESv2/renderer/Renderer.h" |
| 14 | #include "libGLESv2/renderer/ShaderExecutable.h" |
| 15 | #include "libGLESv2/renderer/d3d/DynamicHLSL.h" |
| 16 | #include "libGLESv2/main.h" |
| 17 | |
| 18 | namespace rx |
| 19 | { |
| 20 | |
| 21 | ProgramD3D::ProgramD3D(rx::Renderer *renderer) |
| 22 | : ProgramImpl(), |
| 23 | mRenderer(renderer), |
| 24 | mDynamicHLSL(NULL), |
| 25 | mVertexUniformStorage(NULL), |
| 26 | mFragmentUniformStorage(NULL) |
| 27 | { |
| 28 | mDynamicHLSL = new rx::DynamicHLSL(renderer); |
| 29 | } |
| 30 | |
| 31 | ProgramD3D::~ProgramD3D() |
| 32 | { |
| 33 | reset(); |
| 34 | SafeDelete(mDynamicHLSL); |
| 35 | } |
| 36 | |
| 37 | ProgramD3D *ProgramD3D::makeProgramD3D(ProgramImpl *impl) |
| 38 | { |
| 39 | ASSERT(HAS_DYNAMIC_TYPE(ProgramD3D*, impl)); |
| 40 | return static_cast<ProgramD3D*>(impl); |
| 41 | } |
| 42 | |
| 43 | const ProgramD3D *ProgramD3D::makeProgramD3D(const ProgramImpl *impl) |
| 44 | { |
| 45 | ASSERT(HAS_DYNAMIC_TYPE(const ProgramD3D*, impl)); |
| 46 | return static_cast<const ProgramD3D*>(impl); |
| 47 | } |
| 48 | |
| 49 | void ProgramD3D::initializeUniformStorage(const std::vector<gl::LinkedUniform*> &uniforms) |
| 50 | { |
| 51 | // Compute total default block size |
| 52 | unsigned int vertexRegisters = 0; |
| 53 | unsigned int fragmentRegisters = 0; |
| 54 | for (size_t uniformIndex = 0; uniformIndex < uniforms.size(); uniformIndex++) |
| 55 | { |
| 56 | const gl::LinkedUniform &uniform = *uniforms[uniformIndex]; |
| 57 | |
| 58 | if (!gl::IsSampler(uniform.type)) |
| 59 | { |
| 60 | if (uniform.isReferencedByVertexShader()) |
| 61 | { |
| 62 | vertexRegisters = std::max(vertexRegisters, uniform.vsRegisterIndex + uniform.registerCount); |
| 63 | } |
| 64 | if (uniform.isReferencedByFragmentShader()) |
| 65 | { |
| 66 | fragmentRegisters = std::max(fragmentRegisters, uniform.psRegisterIndex + uniform.registerCount); |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | mVertexUniformStorage = mRenderer->createUniformStorage(vertexRegisters * 16u); |
| 72 | mFragmentUniformStorage = mRenderer->createUniformStorage(fragmentRegisters * 16u); |
| 73 | } |
| 74 | |
| 75 | void ProgramD3D::reset() |
| 76 | { |
| 77 | SafeDelete(mVertexUniformStorage); |
| 78 | SafeDelete(mFragmentUniformStorage); |
| 79 | } |
| 80 | |
| 81 | } |