1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "gpu/command_buffer/client/program_info_manager.h"
6 #include "testing/gtest/include/gtest/gtest.h"
10 uint32
ComputeOffset(const void* start
, const void* position
) {
11 return static_cast<const uint8
*>(position
) -
12 static_cast<const uint8
*>(start
);
15 const GLuint kClientProgramId
= 321;
17 } // namespace anonymous
22 class ProgramInfoManagerTest
: public testing::Test
{
24 ProgramInfoManagerTest() {}
25 ~ProgramInfoManagerTest() override
{}
28 typedef ProgramInfoManager::Program Program
;
30 struct ProgramES2Data
{
31 // TODO(zmo): Also add attrib data.
32 ProgramInfoHeader header
;
33 ProgramInput uniforms
[2];
34 int32_t uniform_loc0
[1];
35 int32_t uniform_loc1
[2];
36 char uniform_name0
[4];
37 char uniform_name1
[8];
40 struct UniformBlocksData
{
41 UniformBlocksHeader header
;
42 UniformBlockInfo entry
[2];
49 struct UniformsES3Data
{
50 UniformsES3Header header
;
51 UniformES3Info entry
[2];
54 struct TransformFeedbackVaryingsData
{
55 TransformFeedbackVaryingsHeader header
;
56 TransformFeedbackVaryingInfo entry
[2];
61 void SetUp() override
{
62 program_info_manager_
.reset(new ProgramInfoManager
);
63 program_info_manager_
->CreateInfo(kClientProgramId
);
65 base::AutoLock
auto_lock(program_info_manager_
->lock_
);
66 program_
= program_info_manager_
->GetProgramInfo(
67 NULL
, kClientProgramId
, ProgramInfoManager::kNone
);
68 ASSERT_TRUE(program_
!= NULL
);
72 void TearDown() override
{}
74 void SetupProgramES2Data(ProgramES2Data
* data
) {
75 // The names needs to be of size 4*k-1 to avoid padding in the struct Data.
76 // This is a testing only problem.
77 const char* kName
[] = { "cow", "bull[0]" };
78 data
->header
.link_status
= 1;
79 data
->header
.num_attribs
= 0;
80 data
->header
.num_uniforms
= 2;
81 data
->uniforms
[0].type
= GL_FLOAT
;
82 data
->uniforms
[0].size
= 1;
83 data
->uniforms
[0].location_offset
=
84 ComputeOffset(data
, &data
->uniform_loc0
);
85 data
->uniforms
[0].name_offset
=
86 ComputeOffset(data
, &data
->uniform_name0
);
87 data
->uniforms
[0].name_length
= strlen(kName
[0]);
88 data
->uniforms
[1].type
= GL_FLOAT_VEC4
;
89 data
->uniforms
[1].size
= 2;
90 data
->uniforms
[1].location_offset
=
91 ComputeOffset(data
, &data
->uniform_loc1
);
92 data
->uniforms
[1].name_offset
=
93 ComputeOffset(data
, &data
->uniform_name1
);
94 data
->uniforms
[1].name_length
= strlen(kName
[1]);
95 data
->uniform_loc0
[0] = 1;
96 data
->uniform_loc1
[0] = 2;
97 data
->uniform_loc1
[1] = 3;
98 memcpy(data
->uniform_name0
, kName
[0], arraysize(data
->uniform_name0
));
99 memcpy(data
->uniform_name1
, kName
[1], arraysize(data
->uniform_name1
));
102 void SetupUniformBlocksData(UniformBlocksData
* data
) {
103 // The names needs to be of size 4*k-1 to avoid padding in the struct Data.
104 // This is a testing only problem.
105 const char* kName
[] = { "cow", "chicken" };
106 const uint32_t kIndices0
[] = { 1, 2 };
107 const uint32_t kIndices1
[] = { 3 };
108 const uint32_t* kIndices
[] = { kIndices0
, kIndices1
};
109 data
->header
.num_uniform_blocks
= 2;
110 data
->entry
[0].binding
= 0;
111 data
->entry
[0].data_size
= 8;
112 data
->entry
[0].name_offset
= ComputeOffset(data
, data
->name0
);
113 data
->entry
[0].name_length
= arraysize(data
->name0
);
114 data
->entry
[0].active_uniforms
= arraysize(data
->indices0
);
115 data
->entry
[0].active_uniform_offset
= ComputeOffset(data
, data
->indices0
);
116 data
->entry
[0].referenced_by_vertex_shader
= static_cast<uint32_t>(true);
117 data
->entry
[0].referenced_by_fragment_shader
= static_cast<uint32_t>(false);
118 data
->entry
[1].binding
= 1;
119 data
->entry
[1].data_size
= 4;
120 data
->entry
[1].name_offset
= ComputeOffset(data
, data
->name1
);
121 data
->entry
[1].name_length
= arraysize(data
->name1
);
122 data
->entry
[1].active_uniforms
= arraysize(data
->indices1
);
123 data
->entry
[1].active_uniform_offset
= ComputeOffset(data
, data
->indices1
);
124 data
->entry
[1].referenced_by_vertex_shader
= static_cast<uint32_t>(false);
125 data
->entry
[1].referenced_by_fragment_shader
= static_cast<uint32_t>(true);
126 memcpy(data
->name0
, kName
[0], arraysize(data
->name0
));
127 data
->indices0
[0] = kIndices
[0][0];
128 data
->indices0
[1] = kIndices
[0][1];
129 memcpy(data
->name1
, kName
[1], arraysize(data
->name1
));
130 data
->indices1
[0] = kIndices
[1][0];
133 void SetupUniformsES3Data(UniformsES3Data
* data
) {
134 data
->header
.num_uniforms
= 2;
135 data
->entry
[0].block_index
= 1;
136 data
->entry
[0].offset
= 2;
137 data
->entry
[0].array_stride
= 3;
138 data
->entry
[0].matrix_stride
= 4;
139 data
->entry
[0].is_row_major
= 0;
140 data
->entry
[1].block_index
= 5;
141 data
->entry
[1].offset
= 6;
142 data
->entry
[1].array_stride
= 7;
143 data
->entry
[1].matrix_stride
= 8;
144 data
->entry
[1].is_row_major
= 1;
147 void SetupTransformFeedbackVaryingsData(TransformFeedbackVaryingsData
* data
) {
148 // The names needs to be of size 4*k-1 to avoid padding in the struct Data.
149 // This is a testing only problem.
150 const char* kName
[] = { "cow", "chicken" };
151 data
->header
.transform_feedback_buffer_mode
= GL_SEPARATE_ATTRIBS
;
152 data
->header
.num_transform_feedback_varyings
= 2;
153 data
->entry
[0].size
= 1;
154 data
->entry
[0].type
= GL_FLOAT_VEC2
;
155 data
->entry
[0].name_offset
= ComputeOffset(data
, data
->name0
);
156 data
->entry
[0].name_length
= arraysize(data
->name0
);
157 data
->entry
[1].size
= 2;
158 data
->entry
[1].type
= GL_FLOAT
;
159 data
->entry
[1].name_offset
= ComputeOffset(data
, data
->name1
);
160 data
->entry
[1].name_length
= arraysize(data
->name1
);
161 memcpy(data
->name0
, kName
[0], arraysize(data
->name0
));
162 memcpy(data
->name1
, kName
[1], arraysize(data
->name1
));
165 scoped_ptr
<ProgramInfoManager
> program_info_manager_
;
169 TEST_F(ProgramInfoManagerTest
, UpdateES2
) {
171 SetupProgramES2Data(&data
);
172 const std::string kNames
[] = { data
.uniform_name0
, data
.uniform_name1
};
173 const int32_t* kLocs
[] = { data
.uniform_loc0
, data
.uniform_loc1
};
174 std::vector
<int8
> result(sizeof(data
));
175 memcpy(&result
[0], &data
, sizeof(data
));
176 EXPECT_FALSE(program_
->IsCached(ProgramInfoManager::kES2
));
177 program_
->UpdateES2(result
);
178 EXPECT_TRUE(program_
->IsCached(ProgramInfoManager::kES2
));
181 EXPECT_TRUE(program_
->GetProgramiv(GL_LINK_STATUS
, ¶ms
));
185 EXPECT_TRUE(program_
->GetProgramiv(GL_ACTIVE_ATTRIBUTES
, ¶ms
));
186 EXPECT_EQ(data
.header
.num_attribs
, static_cast<uint32_t>(params
));
188 EXPECT_TRUE(program_
->GetProgramiv(GL_ACTIVE_ATTRIBUTE_MAX_LENGTH
, ¶ms
));
189 EXPECT_EQ(0, params
);
192 EXPECT_TRUE(program_
->GetProgramiv(GL_ACTIVE_UNIFORMS
, ¶ms
));
193 EXPECT_EQ(data
.header
.num_uniforms
, static_cast<uint32_t>(params
));
194 GLint active_uniform_max_length
= 0;
195 EXPECT_TRUE(program_
->GetProgramiv(
196 GL_ACTIVE_UNIFORM_MAX_LENGTH
, &active_uniform_max_length
));
198 for (uint32_t ii
= 0; ii
< data
.header
.num_uniforms
; ++ii
) {
199 const Program::UniformInfo
* info
= program_
->GetUniformInfo(ii
);
200 EXPECT_TRUE(info
!= NULL
);
201 EXPECT_EQ(data
.uniforms
[ii
].type
, info
->type
);
202 EXPECT_EQ(data
.uniforms
[ii
].size
, info
->size
);
203 EXPECT_LT(kNames
[0].length(),
204 static_cast<size_t>(active_uniform_max_length
));
205 EXPECT_EQ(kNames
[ii
], info
->name
);
206 EXPECT_EQ(kNames
[ii
][kNames
[ii
].length() - 1] == ']', info
->is_array
);
207 EXPECT_EQ(data
.uniforms
[ii
].size
,
208 static_cast<int32_t>(info
->element_locations
.size()));
209 for (int32_t uu
= 0; uu
< data
.uniforms
[ii
].size
; ++uu
) {
210 EXPECT_EQ(kLocs
[ii
][uu
], info
->element_locations
[uu
]);
215 TEST_F(ProgramInfoManagerTest
, UpdateES3UniformBlocks
) {
216 UniformBlocksData data
;
217 SetupUniformBlocksData(&data
);
218 const std::string kName
[] = { data
.name0
, data
.name1
};
219 const uint32_t* kIndices
[] = { data
.indices0
, data
.indices1
};
220 std::vector
<int8
> result(sizeof(data
));
221 memcpy(&result
[0], &data
, sizeof(data
));
222 EXPECT_FALSE(program_
->IsCached(ProgramInfoManager::kES3UniformBlocks
));
223 program_
->UpdateES3UniformBlocks(result
);
224 EXPECT_TRUE(program_
->IsCached(ProgramInfoManager::kES3UniformBlocks
));
226 GLint uniform_block_count
= 0;
227 EXPECT_TRUE(program_
->GetProgramiv(
228 GL_ACTIVE_UNIFORM_BLOCKS
, &uniform_block_count
));
229 EXPECT_EQ(data
.header
.num_uniform_blocks
,
230 static_cast<uint32_t>(uniform_block_count
));
231 GLint max_name_length
= 0;
232 EXPECT_TRUE(program_
->GetProgramiv(
233 GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH
, &max_name_length
));
234 for (uint32_t ii
= 0; ii
< data
.header
.num_uniform_blocks
; ++ii
) {
235 EXPECT_EQ(ii
, program_
->GetUniformBlockIndex(kName
[ii
]));
236 const Program::UniformBlock
* info
= program_
->GetUniformBlock(ii
);
237 EXPECT_TRUE(info
!= NULL
);
238 EXPECT_EQ(data
.entry
[ii
].binding
, info
->binding
);
239 EXPECT_EQ(data
.entry
[ii
].data_size
, info
->data_size
);
240 EXPECT_EQ(data
.entry
[ii
].active_uniforms
,
241 info
->active_uniform_indices
.size());
242 for (uint32_t uu
= 0; uu
< data
.entry
[ii
].active_uniforms
; ++uu
) {
243 EXPECT_EQ(kIndices
[ii
][uu
], info
->active_uniform_indices
[uu
]);
245 EXPECT_EQ(data
.entry
[ii
].referenced_by_vertex_shader
,
246 static_cast<GLboolean
>(info
->referenced_by_vertex_shader
));
247 EXPECT_EQ(data
.entry
[ii
].referenced_by_fragment_shader
,
248 static_cast<GLboolean
>(info
->referenced_by_fragment_shader
));
249 EXPECT_EQ(kName
[ii
], info
->name
);
250 EXPECT_GE(max_name_length
, static_cast<GLint
>(info
->name
.size()) + 1);
253 EXPECT_EQ(GL_INVALID_INDEX
, program_
->GetUniformBlockIndex("BadName"));
254 EXPECT_EQ(NULL
, program_
->GetUniformBlock(data
.header
.num_uniform_blocks
));
257 TEST_F(ProgramInfoManagerTest
, UpdateES3TransformFeedbackVaryings
) {
258 TransformFeedbackVaryingsData data
;
259 SetupTransformFeedbackVaryingsData(&data
);
260 const std::string kName
[] = { data
.name0
, data
.name1
};
261 std::vector
<int8
> result(sizeof(data
));
262 memcpy(&result
[0], &data
, sizeof(data
));
263 EXPECT_FALSE(program_
->IsCached(
264 ProgramInfoManager::kES3TransformFeedbackVaryings
));
265 program_
->UpdateES3TransformFeedbackVaryings(result
);
266 EXPECT_TRUE(program_
->IsCached(
267 ProgramInfoManager::kES3TransformFeedbackVaryings
));
269 GLint transform_feedback_buffer_mode
= 0;
270 EXPECT_TRUE(program_
->GetProgramiv(
271 GL_TRANSFORM_FEEDBACK_BUFFER_MODE
, &transform_feedback_buffer_mode
));
272 EXPECT_EQ(data
.header
.transform_feedback_buffer_mode
,
273 static_cast<uint32_t>(transform_feedback_buffer_mode
));
274 GLint transform_feedback_varying_count
= 0;
275 EXPECT_TRUE(program_
->GetProgramiv(
276 GL_TRANSFORM_FEEDBACK_VARYINGS
, &transform_feedback_varying_count
));
277 EXPECT_EQ(data
.header
.num_transform_feedback_varyings
,
278 static_cast<uint32_t>(transform_feedback_varying_count
));
279 GLint max_name_length
= 0;
280 EXPECT_TRUE(program_
->GetProgramiv(
281 GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH
, &max_name_length
));
282 for (uint32_t ii
= 0; ii
< data
.header
.num_transform_feedback_varyings
;
284 const Program::TransformFeedbackVarying
* varying
=
285 program_
->GetTransformFeedbackVarying(ii
);
286 EXPECT_TRUE(varying
!= NULL
);
287 EXPECT_EQ(data
.entry
[ii
].size
, static_cast<uint32_t>(varying
->size
));
288 EXPECT_EQ(data
.entry
[ii
].type
, varying
->type
);
289 EXPECT_EQ(kName
[ii
], varying
->name
);
290 EXPECT_GE(max_name_length
, static_cast<GLint
>(varying
->name
.size()) + 1);
292 EXPECT_EQ(NULL
, program_
->GetTransformFeedbackVarying(
293 data
.header
.num_transform_feedback_varyings
));
296 TEST_F(ProgramInfoManagerTest
, GetUniformBlockIndexCached
) {
297 UniformBlocksData data
;
298 SetupUniformBlocksData(&data
);
299 std::vector
<int8
> result(sizeof(data
));
300 memcpy(&result
[0], &data
, sizeof(data
));
301 program_
->UpdateES3UniformBlocks(result
);
303 EXPECT_EQ(0u, program_info_manager_
->GetUniformBlockIndex(
304 NULL
, kClientProgramId
, data
.name0
));
305 EXPECT_EQ(1u, program_info_manager_
->GetUniformBlockIndex(
306 NULL
, kClientProgramId
, data
.name1
));
307 EXPECT_EQ(GL_INVALID_INDEX
, program_info_manager_
->GetUniformBlockIndex(
308 NULL
, kClientProgramId
, "BadName"));
311 TEST_F(ProgramInfoManagerTest
, GetActiveUniformBlockNameCached
) {
312 UniformBlocksData data
;
313 SetupUniformBlocksData(&data
);
314 std::vector
<int8
> result(sizeof(data
));
315 memcpy(&result
[0], &data
, sizeof(data
));
316 program_
->UpdateES3UniformBlocks(result
);
318 GLsizei buf_size
= std::max(strlen(data
.name0
), strlen(data
.name1
)) + 1;
319 std::vector
<char> buffer(buf_size
);
321 EXPECT_EQ(true, program_info_manager_
->GetActiveUniformBlockName(
322 NULL
, kClientProgramId
, 0, buf_size
, &length
, &buffer
[0]));
323 EXPECT_EQ(static_cast<GLsizei
>(strlen(data
.name0
)), length
);
324 EXPECT_STREQ(data
.name0
, &buffer
[0]);
326 EXPECT_EQ(true, program_info_manager_
->GetActiveUniformBlockName(
327 NULL
, kClientProgramId
, 1, buf_size
, &length
, &buffer
[0]));
328 EXPECT_EQ(static_cast<GLsizei
>(strlen(data
.name1
)), length
);
329 EXPECT_STREQ(data
.name1
, &buffer
[0]);
331 // Test length == NULL.
332 EXPECT_EQ(true, program_info_manager_
->GetActiveUniformBlockName(
333 NULL
, kClientProgramId
, 0, buf_size
, NULL
, &buffer
[0]));
334 EXPECT_STREQ(data
.name0
, &buffer
[0]);
336 // Test buffer == NULL.
337 EXPECT_EQ(true, program_info_manager_
->GetActiveUniformBlockName(
338 NULL
, kClientProgramId
, 0, buf_size
, &length
, NULL
));
339 EXPECT_EQ(0, length
);
341 // Test buf_size smaller than string size.
342 buf_size
= strlen(data
.name0
);
343 EXPECT_EQ(true, program_info_manager_
->GetActiveUniformBlockName(
344 NULL
, kClientProgramId
, 0, buf_size
, &length
, &buffer
[0]));
345 EXPECT_EQ(buf_size
, length
+ 1);
346 EXPECT_STREQ(std::string(data
.name0
).substr(0, length
).c_str(), &buffer
[0]);
349 TEST_F(ProgramInfoManagerTest
, GetActiveUniformBlockivCached
) {
350 UniformBlocksData data
;
351 SetupUniformBlocksData(&data
);
352 std::vector
<int8
> result(sizeof(data
));
353 memcpy(&result
[0], &data
, sizeof(data
));
354 program_
->UpdateES3UniformBlocks(result
);
355 const char* kName
[] = { data
.name0
, data
.name1
};
356 const uint32_t* kIndices
[] = { data
.indices0
, data
.indices1
};
358 for (uint32_t ii
= 0; ii
< data
.header
.num_uniform_blocks
; ++ii
) {
359 ASSERT_GE(2u, data
.entry
[ii
].active_uniforms
);
361 EXPECT_TRUE(program_info_manager_
->GetActiveUniformBlockiv(
362 NULL
, kClientProgramId
, ii
, GL_UNIFORM_BLOCK_BINDING
, params
));
363 EXPECT_EQ(data
.entry
[ii
].binding
, static_cast<uint32_t>(params
[0]));
365 EXPECT_TRUE(program_info_manager_
->GetActiveUniformBlockiv(
366 NULL
, kClientProgramId
, ii
, GL_UNIFORM_BLOCK_DATA_SIZE
, params
));
367 EXPECT_EQ(data
.entry
[ii
].data_size
, static_cast<uint32_t>(params
[0]));
369 EXPECT_TRUE(program_info_manager_
->GetActiveUniformBlockiv(
370 NULL
, kClientProgramId
, ii
, GL_UNIFORM_BLOCK_NAME_LENGTH
, params
));
371 EXPECT_EQ(strlen(kName
[ii
]) + 1, static_cast<uint32_t>(params
[0]));
373 EXPECT_TRUE(program_info_manager_
->GetActiveUniformBlockiv(
374 NULL
, kClientProgramId
, ii
, GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS
, params
));
375 EXPECT_EQ(data
.entry
[ii
].active_uniforms
, static_cast<uint32_t>(params
[0]));
377 EXPECT_TRUE(program_info_manager_
->GetActiveUniformBlockiv(
378 NULL
, kClientProgramId
, ii
,
379 GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES
, params
));
380 for (uint32_t uu
= 0; uu
< data
.entry
[ii
].active_uniforms
; ++uu
) {
381 EXPECT_EQ(kIndices
[ii
][uu
], static_cast<uint32_t>(params
[uu
]));
384 EXPECT_TRUE(program_info_manager_
->GetActiveUniformBlockiv(
385 NULL
, kClientProgramId
, ii
,
386 GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER
, params
));
387 EXPECT_EQ(data
.entry
[ii
].referenced_by_vertex_shader
,
388 static_cast<uint32_t>(params
[0]));
390 EXPECT_TRUE(program_info_manager_
->GetActiveUniformBlockiv(
391 NULL
, kClientProgramId
, ii
,
392 GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER
, params
));
393 EXPECT_EQ(data
.entry
[ii
].referenced_by_fragment_shader
,
394 static_cast<uint32_t>(params
[0]));
398 TEST_F(ProgramInfoManagerTest
, GetTransformFeedbackVaryingCached
) {
399 TransformFeedbackVaryingsData data
;
400 SetupTransformFeedbackVaryingsData(&data
);
401 std::vector
<int8
> result(sizeof(data
));
402 memcpy(&result
[0], &data
, sizeof(data
));
403 program_
->UpdateES3TransformFeedbackVaryings(result
);
404 const char* kName
[] = { data
.name0
, data
.name1
};
405 GLsizei buf_size
= std::max(strlen(kName
[0]), strlen(kName
[1])) + 1;
406 for (uint32_t ii
= 0; ii
< data
.header
.num_transform_feedback_varyings
;
408 std::vector
<char> buffer(buf_size
);
412 EXPECT_EQ(true, program_info_manager_
->GetTransformFeedbackVarying(
413 NULL
, kClientProgramId
, ii
, buf_size
,
414 &length
, &size
, &type
, &buffer
[0]));
415 EXPECT_EQ(data
.entry
[ii
].size
, static_cast<uint32_t>(size
));
416 EXPECT_EQ(data
.entry
[ii
].type
, static_cast<uint32_t>(type
));
417 EXPECT_STREQ(kName
[ii
], &buffer
[0]);
418 EXPECT_EQ(strlen(kName
[ii
]), static_cast<size_t>(length
));
422 TEST_F(ProgramInfoManagerTest
, GetUniformIndices
) {
424 SetupProgramES2Data(&data
);
425 std::vector
<int8
> result(sizeof(data
));
426 memcpy(&result
[0], &data
, sizeof(data
));
427 program_
->UpdateES2(result
);
430 const char* kNames
[] = { data
.uniform_name0
, data
.uniform_name1
};
431 const GLuint kIndices
[] = { 0, 1 };
432 const GLsizei kCount
= 2;
433 GLuint indices
[kCount
];
434 EXPECT_TRUE(program_info_manager_
->GetUniformIndices(
435 NULL
, kClientProgramId
, kCount
, kNames
, indices
));
436 for (GLsizei ii
= 0; ii
< kCount
; ++ii
) {
437 EXPECT_EQ(kIndices
[ii
], indices
[ii
]);
442 const char* kNames
[] = { data
.uniform_name1
, data
.uniform_name0
};
443 const GLuint kIndices
[] = { 1, 0 };
444 const GLsizei kCount
= 2;
445 GLuint indices
[kCount
];
446 EXPECT_TRUE(program_info_manager_
->GetUniformIndices(
447 NULL
, kClientProgramId
, kCount
, kNames
, indices
));
448 for (GLsizei ii
= 0; ii
< kCount
; ++ii
) {
449 EXPECT_EQ(kIndices
[ii
], indices
[ii
]);
454 const char* kNames
[] = { data
.uniform_name1
, "BadName" };
455 const GLuint kIndices
[] = { 1, GL_INVALID_INDEX
};
456 const GLsizei kCount
= 2;
457 GLuint indices
[kCount
];
458 EXPECT_TRUE(program_info_manager_
->GetUniformIndices(
459 NULL
, kClientProgramId
, kCount
, kNames
, indices
));
460 for (GLsizei ii
= 0; ii
< kCount
; ++ii
) {
461 EXPECT_EQ(kIndices
[ii
], indices
[ii
]);
465 { // Both "foo" and "foo[0]" are considered valid names for an array,
467 const char* kNames
[] = { "bull", "bull[0]", "bull[1]" };
468 const GLuint kIndices
[] = { 1, 1, GL_INVALID_INDEX
};
469 const GLsizei kCount
= 3;
470 GLuint indices
[kCount
];
471 EXPECT_TRUE(program_info_manager_
->GetUniformIndices(
472 NULL
, kClientProgramId
, kCount
, kNames
, indices
));
473 for (GLsizei ii
= 0; ii
< kCount
; ++ii
) {
474 EXPECT_EQ(kIndices
[ii
], indices
[ii
]);
479 TEST_F(ProgramInfoManagerTest
, GetActiveUniformsivCached
) {
480 // ES3 only parameters.
481 UniformsES3Data data_es3
;
482 SetupUniformsES3Data(&data_es3
);
483 std::vector
<int8
> result(sizeof(data_es3
));
484 memcpy(&result
[0], &data_es3
, sizeof(data_es3
));
485 EXPECT_FALSE(program_
->IsCached(ProgramInfoManager::kES3Uniformsiv
));
486 program_
->UpdateES3Uniformsiv(result
);
487 EXPECT_TRUE(program_
->IsCached(ProgramInfoManager::kES3Uniformsiv
));
489 uint32_t count
= data_es3
.header
.num_uniforms
;
490 std::vector
<GLuint
> indices(count
);
491 for (uint32_t ii
= 0; ii
< count
; ++ii
) {
494 std::vector
<GLint
> block_index(count
);
495 EXPECT_TRUE(program_info_manager_
->GetActiveUniformsiv(
496 NULL
, kClientProgramId
, static_cast<GLsizei
>(count
), &indices
[0],
497 GL_UNIFORM_BLOCK_INDEX
, &block_index
[0]));
498 std::vector
<GLint
> offset(count
);
499 EXPECT_TRUE(program_info_manager_
->GetActiveUniformsiv(
500 NULL
, kClientProgramId
, static_cast<GLsizei
>(count
), &indices
[0],
501 GL_UNIFORM_OFFSET
, &offset
[0]));
502 std::vector
<GLint
> array_stride(count
);
503 EXPECT_TRUE(program_info_manager_
->GetActiveUniformsiv(
504 NULL
, kClientProgramId
, static_cast<GLsizei
>(count
), &indices
[0],
505 GL_UNIFORM_ARRAY_STRIDE
, &array_stride
[0]));
506 std::vector
<GLint
> matrix_stride(count
);
507 EXPECT_TRUE(program_info_manager_
->GetActiveUniformsiv(
508 NULL
, kClientProgramId
, static_cast<GLsizei
>(count
), &indices
[0],
509 GL_UNIFORM_MATRIX_STRIDE
, &matrix_stride
[0]));
510 std::vector
<GLint
> is_row_major(count
);
511 EXPECT_TRUE(program_info_manager_
->GetActiveUniformsiv(
512 NULL
, kClientProgramId
, static_cast<GLsizei
>(count
), &indices
[0],
513 GL_UNIFORM_IS_ROW_MAJOR
, &is_row_major
[0]));
515 for (uint32_t ii
= 0; ii
< count
; ++ii
) {
516 EXPECT_EQ(data_es3
.entry
[ii
].block_index
, block_index
[ii
]);
517 EXPECT_EQ(data_es3
.entry
[ii
].offset
, offset
[ii
]);
518 EXPECT_EQ(data_es3
.entry
[ii
].array_stride
, array_stride
[ii
]);
519 EXPECT_EQ(data_es3
.entry
[ii
].matrix_stride
, matrix_stride
[ii
]);
520 EXPECT_EQ(data_es3
.entry
[ii
].is_row_major
, is_row_major
[ii
]);
524 ProgramES2Data data_es2
;
525 SetupProgramES2Data(&data_es2
);
526 result
.resize(sizeof(data_es2
));
527 memcpy(&result
[0], &data_es2
, sizeof(data_es2
));
528 EXPECT_FALSE(program_
->IsCached(ProgramInfoManager::kES2
));
529 program_
->UpdateES2(result
);
530 EXPECT_TRUE(program_
->IsCached(ProgramInfoManager::kES2
));
532 std::vector
<GLint
> size(count
);
533 EXPECT_TRUE(program_info_manager_
->GetActiveUniformsiv(
534 NULL
, kClientProgramId
, static_cast<GLsizei
>(count
), &indices
[0],
535 GL_UNIFORM_SIZE
, &size
[0]));
536 std::vector
<GLint
> type(count
);
537 EXPECT_TRUE(program_info_manager_
->GetActiveUniformsiv(
538 NULL
, kClientProgramId
, static_cast<GLsizei
>(count
), &indices
[0],
539 GL_UNIFORM_TYPE
, &type
[0]));
540 std::vector
<GLint
> name_length(count
);
541 EXPECT_TRUE(program_info_manager_
->GetActiveUniformsiv(
542 NULL
, kClientProgramId
, static_cast<GLsizei
>(count
), &indices
[0],
543 GL_UNIFORM_NAME_LENGTH
, &name_length
[0]));
545 for (uint32_t ii
= 0; ii
< count
; ++ii
) {
546 EXPECT_EQ(data_es2
.uniforms
[ii
].size
, size
[ii
]);
547 EXPECT_EQ(data_es2
.uniforms
[ii
].type
, static_cast<uint32_t>(type
[ii
]));
548 EXPECT_EQ(data_es2
.uniforms
[ii
].name_length
+ 1,
549 static_cast<uint32_t>(name_length
[ii
]));