Avi Drissman | 05dfbc82 | 2022-09-13 21:25:34 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
gman@chromium.org | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef GPU_COMMAND_BUFFER_SERVICE_TEST_HELPER_H_ |
| 6 | #define GPU_COMMAND_BUFFER_SERVICE_TEST_HELPER_H_ |
| 7 | |
avi | f15d60a | 2015-12-21 17:06:33 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | |
kbr | c9f0e10c | 2015-03-31 19:49:12 | [diff] [blame] | 10 | #include <string> |
| 11 | #include <vector> |
| 12 | |
Stephen Nusko | f4e5340 | 2025-07-23 13:39:44 | [diff] [blame] | 13 | #include "base/containers/span.h" |
Antoine Labour | feab239 | 2017-12-21 20:28:39 | [diff] [blame] | 14 | #include "gpu/command_buffer/common/context_creation_attribs.h" |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 15 | #include "gpu/command_buffer/service/shader_translator.h" |
gman@chromium.org | 8af4d5e | 2013-03-15 23:55:33 | [diff] [blame] | 16 | #include "ui/gl/gl_implementation.h" |
gman@chromium.org | e16b025 | 2012-12-07 09:07:49 | [diff] [blame] | 17 | #include "ui/gl/gl_mock.h" |
gman@chromium.org | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 18 | |
| 19 | namespace gpu { |
| 20 | namespace gles2 { |
| 21 | |
zmo@google.com | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 22 | struct DisallowedFeatures; |
gman@chromium.org | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 23 | class Buffer; |
| 24 | class BufferManager; |
kkinnunen | c8b449e158 | 2015-11-02 07:57:51 | [diff] [blame] | 25 | class FeatureInfo; |
kloveless@chromium.org | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 26 | class MockErrorState; |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 27 | class Shader; |
piman@chromium.org | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 28 | class TextureRef; |
gman@chromium.org | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 29 | class TextureManager; |
jbauman@chromium.org | c410da80 | 2011-03-14 19:17:41 | [diff] [blame] | 30 | |
gman@chromium.org | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 31 | class TestHelper { |
| 32 | public: |
| 33 | static const GLuint kServiceBlackTexture2dId = 701; |
kbr@chromium.org | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 34 | static const GLuint kServiceDefaultTexture2dId = 702; |
qiankun.miao | 4e2f0d0 | 2015-09-18 03:34:48 | [diff] [blame] | 35 | static const GLuint kServiceBlackTexture3dId = 703; |
| 36 | static const GLuint kServiceDefaultTexture3dId = 704; |
| 37 | static const GLuint kServiceBlackTexture2dArrayId = 705; |
| 38 | static const GLuint kServiceDefaultTexture2dArrayId = 706; |
| 39 | static const GLuint kServiceBlackTextureCubemapId = 707; |
| 40 | static const GLuint kServiceDefaultTextureCubemapId = 708; |
| 41 | static const GLuint kServiceBlackExternalTextureId = 709; |
| 42 | static const GLuint kServiceDefaultExternalTextureId = 710; |
| 43 | static const GLuint kServiceBlackRectangleTextureId = 711; |
| 44 | static const GLuint kServiceDefaultRectangleTextureId = 712; |
gman@chromium.org | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 45 | |
gman@chromium.org | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 46 | static const GLint kMaxSamples = 4; |
gman@chromium.org | 5094b0f | 2010-11-09 19:45:24 | [diff] [blame] | 47 | static const GLint kMaxRenderbufferSize = 1024; |
gman@chromium.org | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 48 | static const GLint kMaxTextureSize = 2048; |
cwallez | e96e24b | 2016-03-15 00:18:48 | [diff] [blame] | 49 | static const GLint kMaxCubeMapTextureSize = 2048; |
zmo | a2226e4 | 2016-02-24 04:29:09 | [diff] [blame] | 50 | static const GLint kMax3DTextureSize = 1024; |
zmo | 9bdab5d | 2016-05-05 04:35:27 | [diff] [blame] | 51 | static const GLint kMaxArrayTextureLayers = 256; |
sandersd | 9d0bb83 | 2014-12-17 01:24:55 | [diff] [blame] | 52 | static const GLint kMaxRectangleTextureSize = 64; |
gman@chromium.org | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 53 | static const GLint kNumVertexAttribs = 16; |
| 54 | static const GLint kNumTextureUnits = 8; |
| 55 | static const GLint kMaxTextureImageUnits = 8; |
| 56 | static const GLint kMaxVertexTextureImageUnits = 2; |
| 57 | static const GLint kMaxFragmentUniformVectors = 16; |
gman@chromium.org | 915a59a1 | 2010-09-30 21:29:11 | [diff] [blame] | 58 | static const GLint kMaxFragmentUniformComponents = |
| 59 | kMaxFragmentUniformVectors * 4; |
gman@chromium.org | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 60 | static const GLint kMaxVaryingVectors = 8; |
gman@chromium.org | 915a59a1 | 2010-09-30 21:29:11 | [diff] [blame] | 61 | static const GLint kMaxVaryingFloats = kMaxVaryingVectors * 4; |
gman@chromium.org | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 62 | static const GLint kMaxVertexUniformVectors = 128; |
gman@chromium.org | 915a59a1 | 2010-09-30 21:29:11 | [diff] [blame] | 63 | static const GLint kMaxVertexUniformComponents = kMaxVertexUniformVectors * 4; |
cwallez | e96e24b | 2016-03-15 00:18:48 | [diff] [blame] | 64 | static const GLint kMaxVertexOutputComponents = 64; |
| 65 | static const GLint kMaxFragmentInputComponents = 60; |
| 66 | static const GLint kMaxProgramTexelOffset = 7; |
| 67 | static const GLint kMinProgramTexelOffset = -8; |
gman@chromium.org | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 68 | |
zmo | 706399be | 2016-04-21 00:01:08 | [diff] [blame] | 69 | static const GLint kMaxTransformFeedbackSeparateAttribs = 4; |
| 70 | static const GLint kMaxUniformBufferBindings = 24; |
| 71 | static const GLint kUniformBufferOffsetAlignment = 1; |
| 72 | |
gman@chromium.org | 0abf43e3 | 2012-05-10 23:36:23 | [diff] [blame] | 73 | struct AttribInfo { |
| 74 | const char* name; |
| 75 | GLint size; |
| 76 | GLenum type; |
| 77 | GLint location; |
| 78 | }; |
| 79 | |
| 80 | struct UniformInfo { |
| 81 | const char* name; |
| 82 | GLint size; |
| 83 | GLenum type; |
| 84 | GLint fake_location; |
| 85 | GLint real_location; |
gman@chromium.org | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 86 | GLint desired_location; |
gman@chromium.org | 0abf43e3 | 2012-05-10 23:36:23 | [diff] [blame] | 87 | const char* good_name; |
| 88 | }; |
| 89 | |
kkinnunen | c8b449e158 | 2015-11-02 07:57:51 | [diff] [blame] | 90 | struct VaryingInfo { |
| 91 | const char* name; |
| 92 | GLint size; |
| 93 | GLenum type; |
| 94 | GLint fake_location; |
| 95 | GLint real_location; |
| 96 | GLint desired_location; |
| 97 | }; |
kkinnunen | 8cefb23 | 2015-12-04 09:36:31 | [diff] [blame] | 98 | struct ProgramOutputInfo { |
| 99 | const char* name; |
| 100 | GLint size; |
| 101 | GLenum type; |
| 102 | GLint color_name; |
| 103 | GLuint index; |
| 104 | }; |
kkinnunen | c8b449e158 | 2015-11-02 07:57:51 | [diff] [blame] | 105 | |
gman@chromium.org | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 106 | static void SetupContextGroupInitExpectations( |
kylechar | 7a46384 | 2016-05-26 14:46:12 | [diff] [blame] | 107 | ::gl::MockGLInterface* gl, |
zmo@google.com | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 108 | const DisallowedFeatures& disallowed_features, |
oetuaho@nvidia.com | 17a96119 | 2014-02-14 15:20:52 | [diff] [blame] | 109 | const char* extensions, |
vmiura@chromium.org | 5ebf59f | 2014-04-08 03:51:57 | [diff] [blame] | 110 | const char* gl_version, |
kylechar | 933c6fc | 2025-09-04 17:29:47 | [diff] [blame] | 111 | ContextType context_type); |
kylechar | 7a46384 | 2016-05-26 14:46:12 | [diff] [blame] | 112 | static void SetupFeatureInfoInitExpectations(::gl::MockGLInterface* gl, |
| 113 | const char* extensions); |
zmo@chromium.org | 185de2a | 2013-04-04 22:57:11 | [diff] [blame] | 114 | static void SetupFeatureInfoInitExpectationsWithGLVersion( |
kylechar | 7a46384 | 2016-05-26 14:46:12 | [diff] [blame] | 115 | ::gl::MockGLInterface* gl, |
gman@chromium.org | a9e2387 | 2012-05-17 21:50:02 | [diff] [blame] | 116 | const char* extensions, |
sievers@chromium.org | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 117 | const char* gl_renderer, |
bajones | 2c9d718 | 2016-03-11 18:16:28 | [diff] [blame] | 118 | const char* gl_version, |
kainino | e20d23ac | 2016-11-03 01:03:45 | [diff] [blame] | 119 | ContextType context_type); |
Antoine Labour | 20d1620 | 2017-09-05 23:05:29 | [diff] [blame] | 120 | static void SetupTextureManagerInitExpectations( |
| 121 | ::gl::MockGLInterface* gl, |
| 122 | bool is_es3_enabled, |
| 123 | bool is_es3_capable, |
Michael Spang | be9d9eb | 2018-06-21 20:02:04 | [diff] [blame] | 124 | const gfx::ExtensionSet& extensions, |
Antoine Labour | 20d1620 | 2017-09-05 23:05:29 | [diff] [blame] | 125 | bool use_default_textures); |
gman@chromium.org | 1075a53 | 2012-06-13 00:52:33 | [diff] [blame] | 126 | static void SetupTextureManagerDestructionExpectations( |
kylechar | 7a46384 | 2016-05-26 14:46:12 | [diff] [blame] | 127 | ::gl::MockGLInterface* gl, |
qiankun.miao | 4e2f0d0 | 2015-09-18 03:34:48 | [diff] [blame] | 128 | bool is_es3_enabled, |
Michael Spang | be9d9eb | 2018-06-21 20:02:04 | [diff] [blame] | 129 | const gfx::ExtensionSet& extensions, |
vmiura@chromium.org | 5ebf59f | 2014-04-08 03:51:57 | [diff] [blame] | 130 | bool use_default_textures); |
gman@chromium.org | 0abf43e3 | 2012-05-10 23:36:23 | [diff] [blame] | 131 | |
kylechar | 7a46384 | 2016-05-26 14:46:12 | [diff] [blame] | 132 | static void SetupShaderExpectations(::gl::MockGLInterface* gl, |
kkinnunen | c8b449e158 | 2015-11-02 07:57:51 | [diff] [blame] | 133 | const FeatureInfo* feature_info, |
| 134 | AttribInfo* attribs, |
| 135 | size_t num_attribs, |
| 136 | UniformInfo* uniforms, |
| 137 | size_t num_uniforms, |
| 138 | GLuint service_id); |
| 139 | |
| 140 | static void SetupShaderExpectationsWithVaryings( |
kylechar | 7a46384 | 2016-05-26 14:46:12 | [diff] [blame] | 141 | ::gl::MockGLInterface* gl, |
kkinnunen | c8b449e158 | 2015-11-02 07:57:51 | [diff] [blame] | 142 | const FeatureInfo* feature_info, |
| 143 | AttribInfo* attribs, |
| 144 | size_t num_attribs, |
| 145 | UniformInfo* uniforms, |
| 146 | size_t num_uniforms, |
| 147 | VaryingInfo* varyings, |
| 148 | size_t num_varyings, |
Stephen Nusko | f4e5340 | 2025-07-23 13:39:44 | [diff] [blame] | 149 | base::span<ProgramOutputInfo> program_outputs, |
| 150 | size_t spanification_suspected_redundant_num_program_outputs, |
gman@chromium.org | 0abf43e3 | 2012-05-10 23:36:23 | [diff] [blame] | 151 | GLuint service_id); |
| 152 | |
kkinnunen | 8cefb23 | 2015-12-04 09:36:31 | [diff] [blame] | 153 | static void SetupProgramSuccessExpectations( |
kylechar | 7a46384 | 2016-05-26 14:46:12 | [diff] [blame] | 154 | ::gl::MockGLInterface* gl, |
kkinnunen | 8cefb23 | 2015-12-04 09:36:31 | [diff] [blame] | 155 | const FeatureInfo* feature_info, |
| 156 | AttribInfo* attribs, |
| 157 | size_t num_attribs, |
| 158 | UniformInfo* uniforms, |
| 159 | size_t num_uniforms, |
| 160 | VaryingInfo* varyings, |
| 161 | size_t num_varyings, |
Stephen Nusko | f4e5340 | 2025-07-23 13:39:44 | [diff] [blame] | 162 | base::span<ProgramOutputInfo> program_outputs, |
| 163 | size_t spanification_suspected_redundant_num_program_outputs, |
kkinnunen | 8cefb23 | 2015-12-04 09:36:31 | [diff] [blame] | 164 | GLuint service_id); |
dmurph@chromium.org | 65dfc60 | 2012-07-23 20:39:39 | [diff] [blame] | 165 | |
kylechar | 7a46384 | 2016-05-26 14:46:12 | [diff] [blame] | 166 | static void DoBufferData(::gl::MockGLInterface* gl, |
| 167 | MockErrorState* error_state, |
| 168 | BufferManager* manager, |
| 169 | Buffer* buffer, |
| 170 | GLenum target, |
| 171 | GLsizeiptr size, |
| 172 | GLenum usage, |
| 173 | const GLvoid* data, |
| 174 | GLenum error); |
gman@chromium.org | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 175 | |
kylechar | 7a46384 | 2016-05-26 14:46:12 | [diff] [blame] | 176 | static void SetTexParameteriWithExpectations(::gl::MockGLInterface* gl, |
| 177 | MockErrorState* error_state, |
| 178 | TextureManager* manager, |
| 179 | TextureRef* texture_ref, |
| 180 | GLenum pname, |
| 181 | GLint value, |
| 182 | GLenum error); |
gman@chromium.org | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 183 | |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 184 | static void SetShaderStates( |
kylechar | 7a46384 | 2016-05-26 14:46:12 | [diff] [blame] | 185 | ::gl::MockGLInterface* gl, |
kkinnunen | 8cefb23 | 2015-12-04 09:36:31 | [diff] [blame] | 186 | Shader* shader, |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 187 | bool expected_valid, |
| 188 | const std::string* const expected_log_info, |
| 189 | const std::string* const expected_translated_source, |
oetuaho | e6bdcf3 | 2015-05-07 16:45:25 | [diff] [blame] | 190 | const int* const expected_shader_version, |
zmo | 88043c08 | 2014-10-09 20:38:55 | [diff] [blame] | 191 | const AttributeMap* const expected_attrib_map, |
| 192 | const UniformMap* const expected_uniform_map, |
| 193 | const VaryingMap* const expected_varying_map, |
yunchao.he | e4edccd | 2015-11-06 00:45:18 | [diff] [blame] | 194 | const InterfaceBlockMap* const expected_interface_block_map, |
Geoff Lang | 30efb7b | 2017-08-09 14:59:23 | [diff] [blame] | 195 | const OutputVariableList* const expected_output_variable_list, |
| 196 | OptionsAffectingCompilationString* options_affecting_compilation); |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 197 | |
kylechar | 7a46384 | 2016-05-26 14:46:12 | [diff] [blame] | 198 | static void SetShaderStates(::gl::MockGLInterface* gl, |
| 199 | Shader* shader, |
| 200 | bool valid); |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 201 | |
Geoff Lang | 30efb7b | 2017-08-09 14:59:23 | [diff] [blame] | 202 | static void SetShaderStates(::gl::MockGLInterface* gl, |
| 203 | Shader* shader, |
| 204 | bool valid, |
| 205 | const std::string& options_affecting_compilation); |
| 206 | |
zmo | 88043c08 | 2014-10-09 20:38:55 | [diff] [blame] | 207 | static sh::Attribute ConstructAttribute( |
| 208 | GLenum type, GLint array_size, GLenum precision, |
| 209 | bool static_use, const std::string& name); |
| 210 | static sh::Uniform ConstructUniform( |
| 211 | GLenum type, GLint array_size, GLenum precision, |
| 212 | bool static_use, const std::string& name); |
| 213 | static sh::Varying ConstructVarying( |
| 214 | GLenum type, GLint array_size, GLenum precision, |
| 215 | bool static_use, const std::string& name); |
Kai Ninomiya | e9cc630 | 2017-05-19 21:49:13 | [diff] [blame] | 216 | static sh::InterfaceBlockField ConstructInterfaceBlockField( |
| 217 | GLenum type, |
| 218 | GLint array_size, |
| 219 | GLenum precision, |
| 220 | bool static_use, |
| 221 | const std::string& name); |
| 222 | static sh::InterfaceBlock ConstructInterfaceBlock( |
| 223 | GLint array_size, |
| 224 | sh::BlockLayoutType layout, |
| 225 | bool is_row_major_layout, |
| 226 | bool static_use, |
| 227 | const std::string& name, |
| 228 | const std::string& instance_name, |
| 229 | const std::vector<sh::InterfaceBlockField>& fields); |
kkinnunen | 8cefb23 | 2015-12-04 09:36:31 | [diff] [blame] | 230 | static sh::OutputVariable ConstructOutputVariable(GLenum type, |
| 231 | GLint array_size, |
| 232 | GLenum precision, |
| 233 | bool static_use, |
| 234 | const std::string& name); |
zmo | 88043c08 | 2014-10-09 20:38:55 | [diff] [blame] | 235 | |
kbr@chromium.org | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 236 | private: |
kylechar | 7a46384 | 2016-05-26 14:46:12 | [diff] [blame] | 237 | static void SetupTextureInitializationExpectations(::gl::MockGLInterface* gl, |
vmiura@chromium.org | 5ebf59f | 2014-04-08 03:51:57 | [diff] [blame] | 238 | GLenum target, |
| 239 | bool use_default_textures); |
kylechar | 7a46384 | 2016-05-26 14:46:12 | [diff] [blame] | 240 | static void SetupTextureDestructionExpectations(::gl::MockGLInterface* gl, |
vmiura@chromium.org | 5ebf59f | 2014-04-08 03:51:57 | [diff] [blame] | 241 | GLenum target, |
| 242 | bool use_default_textures); |
kbr | c9f0e10c | 2015-03-31 19:49:12 | [diff] [blame] | 243 | |
| 244 | static std::vector<std::string> split_extensions_; |
gman@chromium.org | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 245 | }; |
| 246 | |
gman@chromium.org | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 247 | } // namespace gles2 |
| 248 | } // namespace gpu |
| 249 | |
| 250 | #endif // GPU_COMMAND_BUFFER_SERVICE_TEST_HELPER_H_ |