|
8 | 8 | #include "impeller/renderer/backend/gles/buffer_bindings_gles.h" |
9 | 9 | #include "impeller/renderer/backend/gles/device_buffer_gles.h" |
10 | 10 | #include "impeller/renderer/backend/gles/formats_gles.h" |
| 11 | +#include "impeller/renderer/backend/gles/reactor_gles.h" |
11 | 12 | #include "impeller/renderer/backend/gles/test/mock_gles.h" |
12 | 13 | #include "impeller/renderer/command.h" |
13 | 14 |
|
14 | 15 | namespace impeller { |
15 | 16 | namespace testing { |
| 17 | +namespace { |
| 18 | +const GLint kBlockDataSize = 16; |
| 19 | +} |
16 | 20 |
|
17 | 21 | using ::testing::_; |
18 | 22 |
|
@@ -265,5 +269,97 @@ TEST(BufferBindingsGLESTest, BindVertexAttributesSetsInstanceRateDivisor) { |
265 | 269 | /*instance=*/0)); |
266 | 270 | } |
267 | 271 |
|
| 272 | +namespace { |
| 273 | +class TestWorker : public ReactorGLES::Worker { |
| 274 | + public: |
| 275 | + bool CanReactorReactOnCurrentThreadNow( |
| 276 | + const ReactorGLES& reactor) const override { |
| 277 | + return true; |
| 278 | + } |
| 279 | +}; |
| 280 | +} // namespace |
| 281 | + |
| 282 | +void TestBindUniformBufferRange(size_t buffer_view_length, |
| 283 | + size_t expected_bound_size) { |
| 284 | + BufferBindingsGLES bindings; |
| 285 | + auto mock_gles_impl = std::make_unique<::testing::NiceMock<MockGLESImpl>>(); |
| 286 | + |
| 287 | + const GLuint kProgram = 1; |
| 288 | + |
| 289 | + ON_CALL(*mock_gles_impl, |
| 290 | + GetProgramiv(/*program=*/kProgram, |
| 291 | + /*pname=*/GL_ACTIVE_UNIFORM_BLOCKS, /*params=*/_)) |
| 292 | + .WillByDefault(::testing::SetArgPointee<2>(1)); |
| 293 | + ON_CALL(*mock_gles_impl, |
| 294 | + GetActiveUniformBlockiv(/*program=*/kProgram, |
| 295 | + /*uniformBlockIndex=*/0, |
| 296 | + /*pname=*/GL_UNIFORM_BLOCK_NAME_LENGTH, |
| 297 | + /*params=*/_)) |
| 298 | + .WillByDefault(::testing::SetArgPointee<3>(9)); |
| 299 | + ON_CALL(*mock_gles_impl, |
| 300 | + GetActiveUniformBlockName(/*program=*/kProgram, |
| 301 | + /*uniformBlockIndex=*/0, |
| 302 | + /*bufSize=*/9, /*length=*/_, |
| 303 | + /*uniformBlockName=*/_)) |
| 304 | + .WillByDefault([](GLuint program, GLuint index, GLsizei bufSize, |
| 305 | + GLsizei* length, GLchar* name) { |
| 306 | + *length = 8; |
| 307 | + std::memcpy(name, "FragInfo", 9); |
| 308 | + }); |
| 309 | + ON_CALL( |
| 310 | + *mock_gles_impl, |
| 311 | + GetUniformBlockIndex(/*program=*/kProgram, |
| 312 | + /*uniformBlockName=*/::testing::StrEq("FragInfo"))) |
| 313 | + .WillByDefault(::testing::Return(0)); |
| 314 | + ON_CALL(*mock_gles_impl, |
| 315 | + GetActiveUniformBlockiv(/*program=*/kProgram, |
| 316 | + /*uniformBlockIndex=*/0, |
| 317 | + /*pname=*/GL_UNIFORM_BLOCK_DATA_SIZE, |
| 318 | + /*params=*/_)) |
| 319 | + .WillByDefault(::testing::SetArgPointee<3>(kBlockDataSize)); |
| 320 | + |
| 321 | + EXPECT_CALL(*mock_gles_impl, |
| 322 | + BindBufferRange(/*target=*/GL_UNIFORM_BUFFER, /*index=*/0, |
| 323 | + /*buffer=*/_, /*offset=*/0, |
| 324 | + /*size=*/expected_bound_size)) |
| 325 | + .Times(1); |
| 326 | + |
| 327 | + std::shared_ptr<MockGLES> mock_gl = MockGLES::Init(std::move(mock_gles_impl)); |
| 328 | + ASSERT_TRUE(bindings.ReadUniformsBindings(mock_gl->GetProcTable(), kProgram)); |
| 329 | + |
| 330 | + ProcTableGLES::Resolver resolver = kMockResolverGLES; |
| 331 | + auto proc_table = std::make_unique<ProcTableGLES>(resolver); |
| 332 | + auto worker = std::make_shared<TestWorker>(); |
| 333 | + auto reactor = std::make_shared<ReactorGLES>(std::move(proc_table)); |
| 334 | + reactor->AddWorker(worker); |
| 335 | + |
| 336 | + std::vector<BufferResource> bound_buffers; |
| 337 | + std::vector<TextureAndSampler> bound_textures; |
| 338 | + |
| 339 | + ShaderMetadata shader_metadata = {.name = "FragInfo"}; |
| 340 | + auto backing_store = std::make_unique<Allocation>(); |
| 341 | + ASSERT_TRUE(backing_store->Truncate(Bytes{1024})); |
| 342 | + DeviceBufferGLES device_buffer(DeviceBufferDescriptor{.size = 1024}, reactor, |
| 343 | + std::move(backing_store)); |
| 344 | + BufferView buffer_view(&device_buffer, Range(0, buffer_view_length)); |
| 345 | + bound_buffers.push_back(BufferResource(&shader_metadata, buffer_view)); |
| 346 | + |
| 347 | + EXPECT_TRUE(bindings.BindUniformData(mock_gl->GetProcTable(), bound_textures, |
| 348 | + bound_buffers, Range{0, 0}, |
| 349 | + Range{0, 1})); |
| 350 | +} |
| 351 | + |
| 352 | +TEST(BufferBindingsGLESTest, |
| 353 | + BindUniformBufferUsesMaxOfBufferViewAndBlockDataSize) { |
| 354 | + TestBindUniformBufferRange(/*buffer_view_length=*/4, |
| 355 | + /*expected_bound_size=*/kBlockDataSize); |
| 356 | +} |
| 357 | + |
| 358 | +TEST(BufferBindingsGLESTest, |
| 359 | + BindUniformBufferUsesBufferViewLengthWhenGreaterThanBlockDataSize) { |
| 360 | + TestBindUniformBufferRange(/*buffer_view_length=*/32, |
| 361 | + /*expected_bound_size=*/32); |
| 362 | +} |
| 363 | + |
268 | 364 | } // namespace testing |
269 | 365 | } // namespace impeller |
0 commit comments