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
.num_transform_feedback_varyings
= 2;
152 data
->entry
[0].size
= 1;
153 data
->entry
[0].type
= GL_FLOAT_VEC2
;
154 data
->entry
[0].name_offset
= ComputeOffset(data
, data
->name0
);
155 data
->entry
[0].name_length
= arraysize(data
->name0
);
156 data
->entry
[1].size
= 2;
157 data
->entry
[1].type
= GL_FLOAT
;
158 data
->entry
[1].name_offset
= ComputeOffset(data
, data
->name1
);
159 data
->entry
[1].name_length
= arraysize(data
->name1
);
160 memcpy(data
->name0
, kName
[0], arraysize(data
->name0
));
161 memcpy(data
->name1
, kName
[1], arraysize(data
->name1
));
164 scoped_ptr
<ProgramInfoManager
> program_info_manager_
;
168 TEST_F(ProgramInfoManagerTest
, UpdateES2
) {
170 SetupProgramES2Data(&data
);
171 const std::string kNames
[] = { data
.uniform_name0
, data
.uniform_name1
};
172 const int32_t* kLocs
[] = { data
.uniform_loc0
, data
.uniform_loc1
};
173 std::vector
<int8
> result(sizeof(data
));
174 memcpy(&result
[0], &data
, sizeof(data
));
175 EXPECT_FALSE(program_
->IsCached(ProgramInfoManager::kES2
));
176 program_
->UpdateES2(result
);
177 EXPECT_TRUE(program_
->IsCached(ProgramInfoManager::kES2
));
180 EXPECT_TRUE(program_
->GetProgramiv(GL_LINK_STATUS
, ¶ms
));
184 EXPECT_TRUE(program_
->GetProgramiv(GL_ACTIVE_ATTRIBUTES
, ¶ms
));
185 EXPECT_EQ(data
.header
.num_attribs
, static_cast<uint32_t>(params
));
187 EXPECT_TRUE(program_
->GetProgramiv(GL_ACTIVE_ATTRIBUTE_MAX_LENGTH
, ¶ms
));
188 EXPECT_EQ(0, params
);
191 EXPECT_TRUE(program_
->GetProgramiv(GL_ACTIVE_UNIFORMS
, ¶ms
));
192 EXPECT_EQ(data
.header
.num_uniforms
, static_cast<uint32_t>(params
));
193 GLint active_uniform_max_length
= 0;
194 EXPECT_TRUE(program_
->GetProgramiv(
195 GL_ACTIVE_UNIFORM_MAX_LENGTH
, &active_uniform_max_length
));
197 for (uint32_t ii
= 0; ii
< data
.header
.num_uniforms
; ++ii
) {
198 const Program::UniformInfo
* info
= program_
->GetUniformInfo(ii
);
199 EXPECT_TRUE(info
!= NULL
);
200 EXPECT_EQ(data
.uniforms
[ii
].type
, info
->type
);
201 EXPECT_EQ(data
.uniforms
[ii
].size
, info
->size
);
202 EXPECT_LT(kNames
[0].length(),
203 static_cast<size_t>(active_uniform_max_length
));
204 EXPECT_EQ(kNames
[ii
], info
->name
);
205 EXPECT_EQ(kNames
[ii
][kNames
[ii
].length() - 1] == ']', info
->is_array
);
206 EXPECT_EQ(data
.uniforms
[ii
].size
,
207 static_cast<int32_t>(info
->element_locations
.size()));
208 for (int32_t uu
= 0; uu
< data
.uniforms
[ii
].size
; ++uu
) {
209 EXPECT_EQ(kLocs
[ii
][uu
], info
->element_locations
[uu
]);
214 TEST_F(ProgramInfoManagerTest
, UpdateES3UniformBlocks
) {
215 UniformBlocksData data
;
216 SetupUniformBlocksData(&data
);
217 const std::string kName
[] = { data
.name0
, data
.name1
};
218 const uint32_t* kIndices
[] = { data
.indices0
, data
.indices1
};
219 std::vector
<int8
> result(sizeof(data
));
220 memcpy(&result
[0], &data
, sizeof(data
));
221 EXPECT_FALSE(program_
->IsCached(ProgramInfoManager::kES3UniformBlocks
));
222 program_
->UpdateES3UniformBlocks(result
);
223 EXPECT_TRUE(program_
->IsCached(ProgramInfoManager::kES3UniformBlocks
));
225 GLint uniform_block_count
= 0;
226 EXPECT_TRUE(program_
->GetProgramiv(
227 GL_ACTIVE_UNIFORM_BLOCKS
, &uniform_block_count
));
228 EXPECT_EQ(data
.header
.num_uniform_blocks
,
229 static_cast<uint32_t>(uniform_block_count
));
230 GLint max_name_length
= 0;
231 EXPECT_TRUE(program_
->GetProgramiv(
232 GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH
, &max_name_length
));
233 for (uint32_t ii
= 0; ii
< data
.header
.num_uniform_blocks
; ++ii
) {
234 EXPECT_EQ(ii
, program_
->GetUniformBlockIndex(kName
[ii
]));
235 const Program::UniformBlock
* info
= program_
->GetUniformBlock(ii
);
236 EXPECT_TRUE(info
!= NULL
);
237 EXPECT_EQ(data
.entry
[ii
].binding
, info
->binding
);
238 EXPECT_EQ(data
.entry
[ii
].data_size
, info
->data_size
);
239 EXPECT_EQ(data
.entry
[ii
].active_uniforms
,
240 info
->active_uniform_indices
.size());
241 for (uint32_t uu
= 0; uu
< data
.entry
[ii
].active_uniforms
; ++uu
) {
242 EXPECT_EQ(kIndices
[ii
][uu
], info
->active_uniform_indices
[uu
]);
244 EXPECT_EQ(data
.entry
[ii
].referenced_by_vertex_shader
,
245 static_cast<GLboolean
>(info
->referenced_by_vertex_shader
));
246 EXPECT_EQ(data
.entry
[ii
].referenced_by_fragment_shader
,
247 static_cast<GLboolean
>(info
->referenced_by_fragment_shader
));
248 EXPECT_EQ(kName
[ii
], info
->name
);
249 EXPECT_GE(max_name_length
, static_cast<GLint
>(info
->name
.size()) + 1);
252 EXPECT_EQ(GL_INVALID_INDEX
, program_
->GetUniformBlockIndex("BadName"));
253 EXPECT_EQ(NULL
, program_
->GetUniformBlock(data
.header
.num_uniform_blocks
));
256 TEST_F(ProgramInfoManagerTest
, UpdateES3TransformFeedbackVaryings
) {
257 TransformFeedbackVaryingsData data
;
258 SetupTransformFeedbackVaryingsData(&data
);
259 const std::string kName
[] = { data
.name0
, data
.name1
};
260 std::vector
<int8
> result(sizeof(data
));
261 memcpy(&result
[0], &data
, sizeof(data
));
262 EXPECT_FALSE(program_
->IsCached(
263 ProgramInfoManager::kES3TransformFeedbackVaryings
));
264 program_
->UpdateES3TransformFeedbackVaryings(result
);
265 EXPECT_TRUE(program_
->IsCached(
266 ProgramInfoManager::kES3TransformFeedbackVaryings
));
268 GLint transform_feedback_varying_count
= 0;
269 EXPECT_TRUE(program_
->GetProgramiv(
270 GL_TRANSFORM_FEEDBACK_VARYINGS
, &transform_feedback_varying_count
));
271 EXPECT_EQ(data
.header
.num_transform_feedback_varyings
,
272 static_cast<uint32_t>(transform_feedback_varying_count
));
273 GLint max_name_length
= 0;
274 EXPECT_TRUE(program_
->GetProgramiv(
275 GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH
, &max_name_length
));
276 for (uint32_t ii
= 0; ii
< data
.header
.num_transform_feedback_varyings
;
278 const Program::TransformFeedbackVarying
* varying
=
279 program_
->GetTransformFeedbackVarying(ii
);
280 EXPECT_TRUE(varying
!= NULL
);
281 EXPECT_EQ(data
.entry
[ii
].size
, static_cast<uint32_t>(varying
->size
));
282 EXPECT_EQ(data
.entry
[ii
].type
, varying
->type
);
283 EXPECT_EQ(kName
[ii
], varying
->name
);
284 EXPECT_GE(max_name_length
, static_cast<GLint
>(varying
->name
.size()) + 1);
286 EXPECT_EQ(NULL
, program_
->GetTransformFeedbackVarying(
287 data
.header
.num_transform_feedback_varyings
));
290 TEST_F(ProgramInfoManagerTest
, GetUniformBlockIndexCached
) {
291 UniformBlocksData data
;
292 SetupUniformBlocksData(&data
);
293 std::vector
<int8
> result(sizeof(data
));
294 memcpy(&result
[0], &data
, sizeof(data
));
295 program_
->UpdateES3UniformBlocks(result
);
297 EXPECT_EQ(0u, program_info_manager_
->GetUniformBlockIndex(
298 NULL
, kClientProgramId
, data
.name0
));
299 EXPECT_EQ(1u, program_info_manager_
->GetUniformBlockIndex(
300 NULL
, kClientProgramId
, data
.name1
));
301 EXPECT_EQ(GL_INVALID_INDEX
, program_info_manager_
->GetUniformBlockIndex(
302 NULL
, kClientProgramId
, "BadName"));
305 TEST_F(ProgramInfoManagerTest
, GetActiveUniformBlockNameCached
) {
306 UniformBlocksData data
;
307 SetupUniformBlocksData(&data
);
308 std::vector
<int8
> result(sizeof(data
));
309 memcpy(&result
[0], &data
, sizeof(data
));
310 program_
->UpdateES3UniformBlocks(result
);
312 GLsizei buf_size
= std::max(strlen(data
.name0
), strlen(data
.name1
)) + 1;
313 std::vector
<char> buffer(buf_size
);
315 EXPECT_EQ(true, program_info_manager_
->GetActiveUniformBlockName(
316 NULL
, kClientProgramId
, 0, buf_size
, &length
, &buffer
[0]));
317 EXPECT_EQ(static_cast<GLsizei
>(strlen(data
.name0
)), length
);
318 EXPECT_STREQ(data
.name0
, &buffer
[0]);
320 EXPECT_EQ(true, program_info_manager_
->GetActiveUniformBlockName(
321 NULL
, kClientProgramId
, 1, buf_size
, &length
, &buffer
[0]));
322 EXPECT_EQ(static_cast<GLsizei
>(strlen(data
.name1
)), length
);
323 EXPECT_STREQ(data
.name1
, &buffer
[0]);
325 // Test length == NULL.
326 EXPECT_EQ(true, program_info_manager_
->GetActiveUniformBlockName(
327 NULL
, kClientProgramId
, 0, buf_size
, NULL
, &buffer
[0]));
328 EXPECT_STREQ(data
.name0
, &buffer
[0]);
330 // Test buffer == NULL.
331 EXPECT_EQ(true, program_info_manager_
->GetActiveUniformBlockName(
332 NULL
, kClientProgramId
, 0, buf_size
, &length
, NULL
));
333 EXPECT_EQ(0, length
);
335 // Test buf_size smaller than string size.
336 buf_size
= strlen(data
.name0
);
337 EXPECT_EQ(true, program_info_manager_
->GetActiveUniformBlockName(
338 NULL
, kClientProgramId
, 0, buf_size
, &length
, &buffer
[0]));
339 EXPECT_EQ(buf_size
, length
+ 1);
340 EXPECT_STREQ(std::string(data
.name0
).substr(0, length
).c_str(), &buffer
[0]);
343 TEST_F(ProgramInfoManagerTest
, GetActiveUniformBlockivCached
) {
344 UniformBlocksData data
;
345 SetupUniformBlocksData(&data
);
346 std::vector
<int8
> result(sizeof(data
));
347 memcpy(&result
[0], &data
, sizeof(data
));
348 program_
->UpdateES3UniformBlocks(result
);
349 const char* kName
[] = { data
.name0
, data
.name1
};
350 const uint32_t* kIndices
[] = { data
.indices0
, data
.indices1
};
352 for (uint32_t ii
= 0; ii
< data
.header
.num_uniform_blocks
; ++ii
) {
353 ASSERT_GE(2u, data
.entry
[ii
].active_uniforms
);
355 EXPECT_TRUE(program_info_manager_
->GetActiveUniformBlockiv(
356 NULL
, kClientProgramId
, ii
, GL_UNIFORM_BLOCK_BINDING
, params
));
357 EXPECT_EQ(data
.entry
[ii
].binding
, static_cast<uint32_t>(params
[0]));
359 EXPECT_TRUE(program_info_manager_
->GetActiveUniformBlockiv(
360 NULL
, kClientProgramId
, ii
, GL_UNIFORM_BLOCK_DATA_SIZE
, params
));
361 EXPECT_EQ(data
.entry
[ii
].data_size
, static_cast<uint32_t>(params
[0]));
363 EXPECT_TRUE(program_info_manager_
->GetActiveUniformBlockiv(
364 NULL
, kClientProgramId
, ii
, GL_UNIFORM_BLOCK_NAME_LENGTH
, params
));
365 EXPECT_EQ(strlen(kName
[ii
]) + 1, static_cast<uint32_t>(params
[0]));
367 EXPECT_TRUE(program_info_manager_
->GetActiveUniformBlockiv(
368 NULL
, kClientProgramId
, ii
, GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS
, params
));
369 EXPECT_EQ(data
.entry
[ii
].active_uniforms
, static_cast<uint32_t>(params
[0]));
371 EXPECT_TRUE(program_info_manager_
->GetActiveUniformBlockiv(
372 NULL
, kClientProgramId
, ii
,
373 GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES
, params
));
374 for (uint32_t uu
= 0; uu
< data
.entry
[ii
].active_uniforms
; ++uu
) {
375 EXPECT_EQ(kIndices
[ii
][uu
], static_cast<uint32_t>(params
[uu
]));
378 EXPECT_TRUE(program_info_manager_
->GetActiveUniformBlockiv(
379 NULL
, kClientProgramId
, ii
,
380 GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER
, params
));
381 EXPECT_EQ(data
.entry
[ii
].referenced_by_vertex_shader
,
382 static_cast<uint32_t>(params
[0]));
384 EXPECT_TRUE(program_info_manager_
->GetActiveUniformBlockiv(
385 NULL
, kClientProgramId
, ii
,
386 GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER
, params
));
387 EXPECT_EQ(data
.entry
[ii
].referenced_by_fragment_shader
,
388 static_cast<uint32_t>(params
[0]));
392 TEST_F(ProgramInfoManagerTest
, GetTransformFeedbackVaryingCached
) {
393 TransformFeedbackVaryingsData data
;
394 SetupTransformFeedbackVaryingsData(&data
);
395 std::vector
<int8
> result(sizeof(data
));
396 memcpy(&result
[0], &data
, sizeof(data
));
397 program_
->UpdateES3TransformFeedbackVaryings(result
);
398 const char* kName
[] = { data
.name0
, data
.name1
};
399 GLsizei buf_size
= std::max(strlen(kName
[0]), strlen(kName
[1])) + 1;
400 for (uint32_t ii
= 0; ii
< data
.header
.num_transform_feedback_varyings
;
402 std::vector
<char> buffer(buf_size
);
406 EXPECT_EQ(true, program_info_manager_
->GetTransformFeedbackVarying(
407 NULL
, kClientProgramId
, ii
, buf_size
,
408 &length
, &size
, &type
, &buffer
[0]));
409 EXPECT_EQ(data
.entry
[ii
].size
, static_cast<uint32_t>(size
));
410 EXPECT_EQ(data
.entry
[ii
].type
, static_cast<uint32_t>(type
));
411 EXPECT_STREQ(kName
[ii
], &buffer
[0]);
412 EXPECT_EQ(strlen(kName
[ii
]), static_cast<size_t>(length
));
416 TEST_F(ProgramInfoManagerTest
, GetUniformIndices
) {
418 SetupProgramES2Data(&data
);
419 std::vector
<int8
> result(sizeof(data
));
420 memcpy(&result
[0], &data
, sizeof(data
));
421 program_
->UpdateES2(result
);
424 const char* kNames
[] = { data
.uniform_name0
, data
.uniform_name1
};
425 const GLuint kIndices
[] = { 0, 1 };
426 const GLsizei kCount
= 2;
427 GLuint indices
[kCount
];
428 EXPECT_TRUE(program_info_manager_
->GetUniformIndices(
429 NULL
, kClientProgramId
, kCount
, kNames
, indices
));
430 for (GLsizei ii
= 0; ii
< kCount
; ++ii
) {
431 EXPECT_EQ(kIndices
[ii
], indices
[ii
]);
436 const char* kNames
[] = { data
.uniform_name1
, data
.uniform_name0
};
437 const GLuint kIndices
[] = { 1, 0 };
438 const GLsizei kCount
= 2;
439 GLuint indices
[kCount
];
440 EXPECT_TRUE(program_info_manager_
->GetUniformIndices(
441 NULL
, kClientProgramId
, kCount
, kNames
, indices
));
442 for (GLsizei ii
= 0; ii
< kCount
; ++ii
) {
443 EXPECT_EQ(kIndices
[ii
], indices
[ii
]);
448 const char* kNames
[] = { data
.uniform_name1
, "BadName" };
449 const GLuint kIndices
[] = { 1, GL_INVALID_INDEX
};
450 const GLsizei kCount
= 2;
451 GLuint indices
[kCount
];
452 EXPECT_TRUE(program_info_manager_
->GetUniformIndices(
453 NULL
, kClientProgramId
, kCount
, kNames
, indices
));
454 for (GLsizei ii
= 0; ii
< kCount
; ++ii
) {
455 EXPECT_EQ(kIndices
[ii
], indices
[ii
]);
459 { // Both "foo" and "foo[0]" are considered valid names for an array,
461 const char* kNames
[] = { "bull", "bull[0]", "bull[1]" };
462 const GLuint kIndices
[] = { 1, 1, GL_INVALID_INDEX
};
463 const GLsizei kCount
= 3;
464 GLuint indices
[kCount
];
465 EXPECT_TRUE(program_info_manager_
->GetUniformIndices(
466 NULL
, kClientProgramId
, kCount
, kNames
, indices
));
467 for (GLsizei ii
= 0; ii
< kCount
; ++ii
) {
468 EXPECT_EQ(kIndices
[ii
], indices
[ii
]);
473 TEST_F(ProgramInfoManagerTest
, GetActiveUniformsivCached
) {
474 // ES3 only parameters.
475 UniformsES3Data data_es3
;
476 SetupUniformsES3Data(&data_es3
);
477 std::vector
<int8
> result(sizeof(data_es3
));
478 memcpy(&result
[0], &data_es3
, sizeof(data_es3
));
479 EXPECT_FALSE(program_
->IsCached(ProgramInfoManager::kES3Uniformsiv
));
480 program_
->UpdateES3Uniformsiv(result
);
481 EXPECT_TRUE(program_
->IsCached(ProgramInfoManager::kES3Uniformsiv
));
483 uint32_t count
= data_es3
.header
.num_uniforms
;
484 std::vector
<GLuint
> indices(count
);
485 for (uint32_t ii
= 0; ii
< count
; ++ii
) {
488 std::vector
<GLint
> block_index(count
);
489 EXPECT_TRUE(program_info_manager_
->GetActiveUniformsiv(
490 NULL
, kClientProgramId
, static_cast<GLsizei
>(count
), &indices
[0],
491 GL_UNIFORM_BLOCK_INDEX
, &block_index
[0]));
492 std::vector
<GLint
> offset(count
);
493 EXPECT_TRUE(program_info_manager_
->GetActiveUniformsiv(
494 NULL
, kClientProgramId
, static_cast<GLsizei
>(count
), &indices
[0],
495 GL_UNIFORM_OFFSET
, &offset
[0]));
496 std::vector
<GLint
> array_stride(count
);
497 EXPECT_TRUE(program_info_manager_
->GetActiveUniformsiv(
498 NULL
, kClientProgramId
, static_cast<GLsizei
>(count
), &indices
[0],
499 GL_UNIFORM_ARRAY_STRIDE
, &array_stride
[0]));
500 std::vector
<GLint
> matrix_stride(count
);
501 EXPECT_TRUE(program_info_manager_
->GetActiveUniformsiv(
502 NULL
, kClientProgramId
, static_cast<GLsizei
>(count
), &indices
[0],
503 GL_UNIFORM_MATRIX_STRIDE
, &matrix_stride
[0]));
504 std::vector
<GLint
> is_row_major(count
);
505 EXPECT_TRUE(program_info_manager_
->GetActiveUniformsiv(
506 NULL
, kClientProgramId
, static_cast<GLsizei
>(count
), &indices
[0],
507 GL_UNIFORM_IS_ROW_MAJOR
, &is_row_major
[0]));
509 for (uint32_t ii
= 0; ii
< count
; ++ii
) {
510 EXPECT_EQ(data_es3
.entry
[ii
].block_index
, block_index
[ii
]);
511 EXPECT_EQ(data_es3
.entry
[ii
].offset
, offset
[ii
]);
512 EXPECT_EQ(data_es3
.entry
[ii
].array_stride
, array_stride
[ii
]);
513 EXPECT_EQ(data_es3
.entry
[ii
].matrix_stride
, matrix_stride
[ii
]);
514 EXPECT_EQ(data_es3
.entry
[ii
].is_row_major
, is_row_major
[ii
]);
518 ProgramES2Data data_es2
;
519 SetupProgramES2Data(&data_es2
);
520 result
.resize(sizeof(data_es2
));
521 memcpy(&result
[0], &data_es2
, sizeof(data_es2
));
522 EXPECT_FALSE(program_
->IsCached(ProgramInfoManager::kES2
));
523 program_
->UpdateES2(result
);
524 EXPECT_TRUE(program_
->IsCached(ProgramInfoManager::kES2
));
526 std::vector
<GLint
> size(count
);
527 EXPECT_TRUE(program_info_manager_
->GetActiveUniformsiv(
528 NULL
, kClientProgramId
, static_cast<GLsizei
>(count
), &indices
[0],
529 GL_UNIFORM_SIZE
, &size
[0]));
530 std::vector
<GLint
> type(count
);
531 EXPECT_TRUE(program_info_manager_
->GetActiveUniformsiv(
532 NULL
, kClientProgramId
, static_cast<GLsizei
>(count
), &indices
[0],
533 GL_UNIFORM_TYPE
, &type
[0]));
534 std::vector
<GLint
> name_length(count
);
535 EXPECT_TRUE(program_info_manager_
->GetActiveUniformsiv(
536 NULL
, kClientProgramId
, static_cast<GLsizei
>(count
), &indices
[0],
537 GL_UNIFORM_NAME_LENGTH
, &name_length
[0]));
539 for (uint32_t ii
= 0; ii
< count
; ++ii
) {
540 EXPECT_EQ(data_es2
.uniforms
[ii
].size
, size
[ii
]);
541 EXPECT_EQ(data_es2
.uniforms
[ii
].type
, static_cast<uint32_t>(type
[ii
]));
542 EXPECT_EQ(data_es2
.uniforms
[ii
].name_length
+ 1,
543 static_cast<uint32_t>(name_length
[ii
]));