blob: 50bdc580d3b829a6a2f25e15e54a631629272da3 [file] [log] [blame]
Brandon Jonesc9610c52014-08-25 17:02:59 -07001//
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.h: Defines the rx::ProgramD3D class which implements rx::ProgramImpl.
8
9#ifndef LIBGLESV2_RENDERER_PROGRAMD3D_H_
10#define LIBGLESV2_RENDERER_PROGRAMD3D_H_
11
12#include "libGLESv2/renderer/ProgramImpl.h"
13
Brandon Jones22502d52014-08-29 16:58:36 -070014#include <string>
15#include <vector>
16
Brandon Jonesc9610c52014-08-25 17:02:59 -070017namespace gl
18{
19struct LinkedUniform;
Brandon Jones22502d52014-08-29 16:58:36 -070020struct VariableLocation;
Brandon Jonesc9610c52014-08-25 17:02:59 -070021struct VertexFormat;
22}
23
24namespace rx
25{
26
27class UniformStorage;
28
29class ProgramD3D : public ProgramImpl
30{
31 public:
32 ProgramD3D(rx::Renderer *renderer);
33 virtual ~ProgramD3D();
34
35 static ProgramD3D *makeProgramD3D(ProgramImpl *impl);
36 static const ProgramD3D *makeProgramD3D(const ProgramImpl *impl);
37
Brandon Jones22502d52014-08-29 16:58:36 -070038 const std::vector<rx::PixelShaderOutputVariable> &getPixelShaderKey() { return mPixelShaderKey; }
Brandon Jones44151a92014-09-10 11:32:25 -070039 int getShaderVersion() const { return mShaderVersion; }
Brandon Joneseb994362014-09-24 10:27:28 -070040 GLenum getTransformFeedbackBufferMode() const { return mTransformFeedbackBufferMode; }
41 std::vector<gl::LinkedVarying> &getTransformFeedbackLinkedVaryings() { return mTransformFeedbackLinkedVaryings; }
42 sh::Attribute *getShaderAttributes() { return mShaderAttributes; }
Brandon Jones44151a92014-09-10 11:32:25 -070043
Brandon Joneseb994362014-09-24 10:27:28 -070044 bool usesPointSize() const { return mUsesPointSize; }
Brandon Jones44151a92014-09-10 11:32:25 -070045 bool usesPointSpriteEmulation() const;
46 bool usesGeometryShader() const;
Brandon Jones22502d52014-08-29 16:58:36 -070047
48 GLenum getBinaryFormat() { return GL_PROGRAM_BINARY_ANGLE; }
49 bool load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream);
50 bool save(gl::BinaryOutputStream *stream);
51
Brandon Joneseb994362014-09-24 10:27:28 -070052 ShaderExecutable *getPixelExecutableForFramebuffer(const gl::Framebuffer *fbo);
53 ShaderExecutable *getPixelExecutableForOutputLayout(const std::vector<GLenum> &outputLayout);
54 ShaderExecutable *getVertexExecutableForInputLayout(const gl::VertexFormat inputLayout[gl::MAX_VERTEX_ATTRIBS]);
55 ShaderExecutable *getGeometryExecutable() const { return mGeometryExecutable; }
56
57 bool compileProgramExecutables(gl::InfoLog &infoLog, gl::Shader *fragmentShader, gl::Shader *vertexShader,
58 int registers);
Brandon Jones22502d52014-08-29 16:58:36 -070059
60 bool link(gl::InfoLog &infoLog, gl::Shader *fragmentShader, gl::Shader *vertexShader,
Brandon Joneseb994362014-09-24 10:27:28 -070061 const std::vector<std::string> &transformFeedbackVaryings, GLenum transformFeedbackBufferMode,
62 int *registers, std::vector<gl::LinkedVarying> *linkedVaryings,
63 std::map<int, gl::VariableLocation> *outputVariables, const gl::Caps &caps);
Brandon Jonesc9610c52014-08-25 17:02:59 -070064
Brandon Jones44151a92014-09-10 11:32:25 -070065 void getInputLayoutSignature(const gl::VertexFormat inputLayout[], GLenum signature[]) const;
66
Brandon Jonesc9610c52014-08-25 17:02:59 -070067 void initializeUniformStorage(const std::vector<gl::LinkedUniform*> &uniforms);
Brandon Jones18bd4102014-09-22 14:21:44 -070068 gl::Error applyUniforms(const std::vector<gl::LinkedUniform*> &uniforms);
69 gl::Error applyUniformBuffers(const std::vector<gl::UniformBlock*> uniformBlocks, const std::vector<gl::Buffer*> boundBuffers,
70 const gl::Caps &caps);
71 bool assignUniformBlockRegister(gl::InfoLog &infoLog, gl::UniformBlock *uniformBlock, GLenum shader,
72 unsigned int registerIndex, const gl::Caps &caps);
73 unsigned int getReservedUniformVectors(GLenum shader);
Brandon Jonesc9610c52014-08-25 17:02:59 -070074
75 const UniformStorage &getVertexUniformStorage() const { return *mVertexUniformStorage; }
76 const UniformStorage &getFragmentUniformStorage() const { return *mFragmentUniformStorage; }
77
78 void reset();
79
80 private:
81 DISALLOW_COPY_AND_ASSIGN(ProgramD3D);
82
Brandon Joneseb994362014-09-24 10:27:28 -070083 class VertexExecutable
84 {
85 public:
86 VertexExecutable(const gl::VertexFormat inputLayout[gl::MAX_VERTEX_ATTRIBS],
87 const GLenum signature[gl::MAX_VERTEX_ATTRIBS],
88 rx::ShaderExecutable *shaderExecutable);
89 ~VertexExecutable();
90
91 bool matchesSignature(const GLenum convertedLayout[gl::MAX_VERTEX_ATTRIBS]) const;
92
93 const gl::VertexFormat *inputs() const { return mInputs; }
94 const GLenum *signature() const { return mSignature; }
95 rx::ShaderExecutable *shaderExecutable() const { return mShaderExecutable; }
96
97 private:
98 gl::VertexFormat mInputs[gl::MAX_VERTEX_ATTRIBS];
99 GLenum mSignature[gl::MAX_VERTEX_ATTRIBS];
100 rx::ShaderExecutable *mShaderExecutable;
101 };
102
103 class PixelExecutable
104 {
105 public:
106 PixelExecutable(const std::vector<GLenum> &outputSignature, rx::ShaderExecutable *shaderExecutable);
107 ~PixelExecutable();
108
109 bool matchesSignature(const std::vector<GLenum> &signature) const { return mOutputSignature == signature; }
110
111 const std::vector<GLenum> &outputSignature() const { return mOutputSignature; }
112 rx::ShaderExecutable *shaderExecutable() const { return mShaderExecutable; }
113
114 private:
115 std::vector<GLenum> mOutputSignature;
116 rx::ShaderExecutable *mShaderExecutable;
117 };
118
Brandon Jonesc9610c52014-08-25 17:02:59 -0700119 Renderer *mRenderer;
120 DynamicHLSL *mDynamicHLSL;
121
Brandon Joneseb994362014-09-24 10:27:28 -0700122 std::vector<VertexExecutable *> mVertexExecutables;
123 std::vector<PixelExecutable *> mPixelExecutables;
124 rx::ShaderExecutable *mGeometryExecutable;
125
Brandon Jones22502d52014-08-29 16:58:36 -0700126 std::string mVertexHLSL;
127 rx::D3DWorkaroundType mVertexWorkarounds;
128
129 std::string mPixelHLSL;
130 rx::D3DWorkaroundType mPixelWorkarounds;
131 bool mUsesFragDepth;
132 std::vector<rx::PixelShaderOutputVariable> mPixelShaderKey;
133
Brandon Jones44151a92014-09-10 11:32:25 -0700134 bool mUsesPointSize;
135
Brandon Jonesc9610c52014-08-25 17:02:59 -0700136 UniformStorage *mVertexUniformStorage;
137 UniformStorage *mFragmentUniformStorage;
Brandon Jones44151a92014-09-10 11:32:25 -0700138
Brandon Joneseb994362014-09-24 10:27:28 -0700139 GLenum mTransformFeedbackBufferMode;
140 std::vector<gl::LinkedVarying> mTransformFeedbackLinkedVaryings;
141
142 sh::Attribute mShaderAttributes[gl::MAX_VERTEX_ATTRIBS];
143
Brandon Jones44151a92014-09-10 11:32:25 -0700144 int mShaderVersion;
Brandon Jonesc9610c52014-08-25 17:02:59 -0700145};
146
147}
148
149#endif // LIBGLESV2_RENDERER_PROGRAMD3D_H_