Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(459)

Side by Side Diff: cc/resources/resource_provider.cc

Issue 2128773002: cc: Do not verify resource sync tokens unnecessarily. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: set sync token after verification Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/resources/resource_provider.h" 5 #include "cc/resources/resource_provider.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 1349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 DCHECK(!delegated_sync_points_required_ || 1360 DCHECK(!delegated_sync_points_required_ ||
1361 Resource::LOCALLY_USED != resource->synchronization_state()); 1361 Resource::LOCALLY_USED != resource->synchronization_state());
1362 1362
1363 resources.push_back(resource); 1363 resources.push_back(resource);
1364 } 1364 }
1365 1365
1366 // Lazily create any mailboxes and verify all unverified sync tokens. 1366 // Lazily create any mailboxes and verify all unverified sync tokens.
1367 std::vector<GLbyte*> unverified_sync_tokens; 1367 std::vector<GLbyte*> unverified_sync_tokens;
1368 std::vector<Resource*> need_synchronization_resources; 1368 std::vector<Resource*> need_synchronization_resources;
1369 for (Resource* resource : resources) { 1369 for (Resource* resource : resources) {
1370 if (!IsGpuResourceType(resource->type))
1371 continue;
1372
1370 CreateMailboxAndBindResource(gl, resource); 1373 CreateMailboxAndBindResource(gl, resource);
1371 1374
1372 if (delegated_sync_points_required_ && resource->needs_sync_token()) { 1375 if (delegated_sync_points_required_) {
1373 need_synchronization_resources.push_back(resource); 1376 if (resource->needs_sync_token()) {
1374 } else if (resource->mailbox().HasSyncToken() && 1377 need_synchronization_resources.push_back(resource);
1375 !resource->mailbox().sync_token().verified_flush()) { 1378 } else if (resource->mailbox().HasSyncToken() &&
1376 unverified_sync_tokens.push_back(resource->GetSyncTokenData()); 1379 !resource->mailbox().sync_token().verified_flush()) {
1380 unverified_sync_tokens.push_back(resource->GetSyncTokenData());
1381 }
1377 } 1382 }
1378 } 1383 }
1379 1384
1380 // Insert sync point to synchronize the mailbox creation or bound textures. 1385 // Insert sync point to synchronize the mailbox creation or bound textures.
1381 gpu::SyncToken new_sync_token; 1386 gpu::SyncToken new_sync_token;
1382 if (gl) { 1387 if (!need_synchronization_resources.empty()) {
1383 if (!need_synchronization_resources.empty()) { 1388 DCHECK(delegated_sync_points_required_);
1384 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); 1389 DCHECK(gl);
1385 gl->OrderingBarrierCHROMIUM(); 1390 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM();
1386 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, new_sync_token.GetData()); 1391 gl->OrderingBarrierCHROMIUM();
1387 unverified_sync_tokens.push_back(new_sync_token.GetData()); 1392 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, new_sync_token.GetData());
1388 } 1393 unverified_sync_tokens.push_back(new_sync_token.GetData());
1394 }
1389 1395
1390 if (!unverified_sync_tokens.empty()) { 1396 if (!unverified_sync_tokens.empty()) {
1391 gl->VerifySyncTokensCHROMIUM(unverified_sync_tokens.data(), 1397 DCHECK(delegated_sync_points_required_);
1392 unverified_sync_tokens.size()); 1398 DCHECK(gl);
1393 } 1399 gl->VerifySyncTokensCHROMIUM(unverified_sync_tokens.data(),
1400 unverified_sync_tokens.size());
1394 } 1401 }
1402
1403 // Set sync token after verification.
1395 for (Resource* resource : need_synchronization_resources) { 1404 for (Resource* resource : need_synchronization_resources) {
1405 DCHECK(IsGpuResourceType(resource->type));
1396 resource->UpdateSyncToken(new_sync_token); 1406 resource->UpdateSyncToken(new_sync_token);
1397 resource->SetSynchronized(); 1407 resource->SetSynchronized();
1398 } 1408 }
1399 1409
1400 // Transfer Resources 1410 // Transfer Resources
1401 DCHECK_EQ(resources.size(), resource_ids.size()); 1411 DCHECK_EQ(resources.size(), resource_ids.size());
1402 for (size_t i = 0; i < resources.size(); ++i) { 1412 for (size_t i = 0; i < resources.size(); ++i) {
1403 Resource* source = resources[i]; 1413 Resource* source = resources[i];
1404 const ResourceId id = resource_ids[i]; 1414 const ResourceId id = resource_ids[i];
1405 1415
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1543 for (const auto& children : resources_for_child) { 1553 for (const auto& children : resources_for_child) {
1544 ChildMap::iterator child_it = children_.find(children.first); 1554 ChildMap::iterator child_it = children_.find(children.first);
1545 DCHECK(child_it != children_.end()); 1555 DCHECK(child_it != children_.end());
1546 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, children.second); 1556 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, children.second);
1547 } 1557 }
1548 } 1558 }
1549 1559
1550 void ResourceProvider::CreateMailboxAndBindResource( 1560 void ResourceProvider::CreateMailboxAndBindResource(
1551 gpu::gles2::GLES2Interface* gl, 1561 gpu::gles2::GLES2Interface* gl,
1552 Resource* resource) { 1562 Resource* resource) {
1553 if (resource->type != RESOURCE_TYPE_BITMAP) { 1563 DCHECK(IsGpuResourceType(resource->type));
1554 if (!resource->mailbox().IsValid()) { 1564 DCHECK(gl);
1555 LazyCreate(resource);
1556 1565
1557 gpu::MailboxHolder mailbox_holder; 1566 if (!resource->mailbox().IsValid()) {
1558 mailbox_holder.texture_target = resource->target; 1567 LazyCreate(resource);
1559 gl->GenMailboxCHROMIUM(mailbox_holder.mailbox.name);
1560 gl->ProduceTextureDirectCHROMIUM(resource->gl_id,
1561 mailbox_holder.texture_target,
1562 mailbox_holder.mailbox.name);
1563 resource->set_mailbox(TextureMailbox(mailbox_holder));
1564 }
1565 1568
1566 if (resource->image_id && resource->dirty_image) { 1569 gpu::MailboxHolder mailbox_holder;
1567 DCHECK(resource->gl_id); 1570 mailbox_holder.texture_target = resource->target;
1568 DCHECK(resource->origin == Resource::INTERNAL); 1571 gl->GenMailboxCHROMIUM(mailbox_holder.mailbox.name);
1569 BindImageForSampling(resource); 1572 gl->ProduceTextureDirectCHROMIUM(resource->gl_id,
1570 } 1573 mailbox_holder.texture_target,
1574 mailbox_holder.mailbox.name);
1575 resource->set_mailbox(TextureMailbox(mailbox_holder));
1576 }
1577
1578 if (resource->image_id && resource->dirty_image) {
1579 DCHECK(resource->gl_id);
1580 DCHECK(resource->origin == Resource::INTERNAL);
1581 BindImageForSampling(resource);
1571 } 1582 }
1572 } 1583 }
1573 1584
1574 void ResourceProvider::TransferResource(Resource* source, 1585 void ResourceProvider::TransferResource(Resource* source,
1575 ResourceId id, 1586 ResourceId id,
1576 TransferableResource* resource) { 1587 TransferableResource* resource) {
1577 DCHECK(!source->locked_for_write); 1588 DCHECK(!source->locked_for_write);
1578 DCHECK(!source->lock_for_read_count); 1589 DCHECK(!source->lock_for_read_count);
1579 DCHECK(source->origin != Resource::EXTERNAL || source->mailbox().IsValid()); 1590 DCHECK(source->origin != Resource::EXTERNAL || source->mailbox().IsValid());
1580 DCHECK(source->allocated); 1591 DCHECK(source->allocated);
(...skipping 26 matching lines...) Expand all
1607 const ResourceIdArray& unused) { 1618 const ResourceIdArray& unused) {
1608 DCHECK(thread_checker_.CalledOnValidThread()); 1619 DCHECK(thread_checker_.CalledOnValidThread());
1609 DCHECK(child_it != children_.end()); 1620 DCHECK(child_it != children_.end());
1610 Child* child_info = &child_it->second; 1621 Child* child_info = &child_it->second;
1611 1622
1612 if (unused.empty() && !child_info->marked_for_deletion) 1623 if (unused.empty() && !child_info->marked_for_deletion)
1613 return; 1624 return;
1614 1625
1615 ReturnedResourceArray to_return; 1626 ReturnedResourceArray to_return;
1616 to_return.reserve(unused.size()); 1627 to_return.reserve(unused.size());
1628 std::vector<ReturnedResource*> need_synchronization_resources;
1617 std::vector<GLbyte*> unverified_sync_tokens; 1629 std::vector<GLbyte*> unverified_sync_tokens;
1618 1630
1619 bool need_sync_token = false;
1620 GLES2Interface* gl = ContextGL(); 1631 GLES2Interface* gl = ContextGL();
1632
1621 for (ResourceId local_id : unused) { 1633 for (ResourceId local_id : unused) {
1622 ResourceMap::iterator it = resources_.find(local_id); 1634 ResourceMap::iterator it = resources_.find(local_id);
1623 CHECK(it != resources_.end()); 1635 CHECK(it != resources_.end());
1624 Resource& resource = it->second; 1636 Resource& resource = it->second;
1625 1637
1626 DCHECK(!resource.locked_for_write); 1638 DCHECK(!resource.locked_for_write);
1627 DCHECK(child_info->parent_to_child_map.count(local_id)); 1639 DCHECK(child_info->parent_to_child_map.count(local_id));
1628 1640
1629 ResourceId child_id = child_info->parent_to_child_map[local_id]; 1641 ResourceId child_id = child_info->parent_to_child_map[local_id];
1630 DCHECK(child_info->child_to_parent_map.count(child_id)); 1642 DCHECK(child_info->child_to_parent_map.count(child_id));
(...skipping 13 matching lines...) Expand all
1644 // the branch above too, where the resource is locked or still exported. 1656 // the branch above too, where the resource is locked or still exported.
1645 if (style != FOR_SHUTDOWN && !child_info->marked_for_deletion) { 1657 if (style != FOR_SHUTDOWN && !child_info->marked_for_deletion) {
1646 // Defer this resource deletion. 1658 // Defer this resource deletion.
1647 resource.marked_for_deletion = true; 1659 resource.marked_for_deletion = true;
1648 continue; 1660 continue;
1649 } 1661 }
1650 // We can't postpone the deletion, so we'll have to lose it. 1662 // We can't postpone the deletion, so we'll have to lose it.
1651 is_lost = true; 1663 is_lost = true;
1652 } 1664 }
1653 1665
1654 if (gl && resource.filter != resource.original_filter) { 1666 if (IsGpuResourceType(resource.type) &&
1667 resource.filter != resource.original_filter) {
1655 DCHECK(resource.target); 1668 DCHECK(resource.target);
1656 DCHECK(resource.gl_id); 1669 DCHECK(resource.gl_id);
1657 1670 DCHECK(gl);
1658 gl->BindTexture(resource.target, resource.gl_id); 1671 gl->BindTexture(resource.target, resource.gl_id);
1659 gl->TexParameteri(resource.target, GL_TEXTURE_MIN_FILTER, 1672 gl->TexParameteri(resource.target, GL_TEXTURE_MIN_FILTER,
1660 resource.original_filter); 1673 resource.original_filter);
1661 gl->TexParameteri(resource.target, GL_TEXTURE_MAG_FILTER, 1674 gl->TexParameteri(resource.target, GL_TEXTURE_MAG_FILTER,
1662 resource.original_filter); 1675 resource.original_filter);
1663 resource.SetLocallyUsed(); 1676 resource.SetLocallyUsed();
1664 } 1677 }
1665 1678
1666 ReturnedResource returned; 1679 ReturnedResource returned;
1667 returned.id = child_id; 1680 returned.id = child_id;
1668 if (resource.needs_sync_token()) 1681 returned.sync_token = resource.mailbox().sync_token();
1669 need_sync_token = true;
1670 else
1671 returned.sync_token = resource.mailbox().sync_token();
1672
1673 returned.count = resource.imported_count; 1682 returned.count = resource.imported_count;
1674 returned.lost = is_lost; 1683 returned.lost = is_lost;
1675 to_return.push_back(returned); 1684 to_return.push_back(returned);
1676 1685
1686 if (IsGpuResourceType(resource.type) && child_info->needs_sync_tokens) {
1687 if (resource.needs_sync_token()) {
1688 need_synchronization_resources.push_back(&to_return.back());
1689 } else if (returned.sync_token.HasData() &&
1690 !returned.sync_token.verified_flush()) {
1691 // Before returning any sync tokens, they must be verified.
1692 unverified_sync_tokens.push_back(returned.sync_token.GetData());
1693 }
1694 }
1695
1677 child_info->parent_to_child_map.erase(local_id); 1696 child_info->parent_to_child_map.erase(local_id);
1678 child_info->child_to_parent_map.erase(child_id); 1697 child_info->child_to_parent_map.erase(child_id);
1679 resource.imported_count = 0; 1698 resource.imported_count = 0;
1680 DeleteResourceInternal(it, style); 1699 DeleteResourceInternal(it, style);
1681
1682 // Before returning any sync tokens, they must be verified. Note that we
1683 // need to verify the sync token inside of the "to_return" array.
1684 if (to_return.back().sync_token.HasData() &&
1685 !to_return.back().sync_token.verified_flush()) {
1686 unverified_sync_tokens.push_back(to_return.back().sync_token.GetData());
1687 }
1688 } 1700 }
1689 1701
1690 gpu::SyncToken new_sync_token; 1702 gpu::SyncToken new_sync_token;
1691 if (need_sync_token && child_info->needs_sync_tokens) { 1703 if (!need_synchronization_resources.empty()) {
1704 DCHECK(child_info->needs_sync_tokens);
1692 DCHECK(gl); 1705 DCHECK(gl);
1693 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); 1706 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM();
1694 gl->OrderingBarrierCHROMIUM(); 1707 gl->OrderingBarrierCHROMIUM();
1695 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, new_sync_token.GetData()); 1708 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, new_sync_token.GetData());
1696 unverified_sync_tokens.push_back(new_sync_token.GetData()); 1709 unverified_sync_tokens.push_back(new_sync_token.GetData());
1697 } 1710 }
1698 1711
1699 if (!unverified_sync_tokens.empty()) { 1712 if (!unverified_sync_tokens.empty()) {
1713 DCHECK(child_info->needs_sync_tokens);
1700 DCHECK(gl); 1714 DCHECK(gl);
1701 gl->VerifySyncTokensCHROMIUM(unverified_sync_tokens.data(), 1715 gl->VerifySyncTokensCHROMIUM(unverified_sync_tokens.data(),
1702 unverified_sync_tokens.size()); 1716 unverified_sync_tokens.size());
1703 } 1717 }
1704 1718
1705 if (new_sync_token.HasData()) { 1719 // Set sync token after verification.
1706 DCHECK(need_sync_token && child_info->needs_sync_tokens); 1720 for (ReturnedResource* returned : need_synchronization_resources)
1707 for (ReturnedResource& returned_resource : to_return) { 1721 returned->sync_token = new_sync_token;
1708 if (!returned_resource.sync_token.HasData())
1709 returned_resource.sync_token = new_sync_token;
1710 }
1711 }
1712 1722
1713 if (!to_return.empty()) 1723 if (!to_return.empty())
1714 child_info->return_callback.Run(to_return, 1724 child_info->return_callback.Run(to_return,
1715 blocking_main_thread_task_runner_); 1725 blocking_main_thread_task_runner_);
1716 1726
1717 if (child_info->marked_for_deletion && 1727 if (child_info->marked_for_deletion &&
1718 child_info->parent_to_child_map.empty()) { 1728 child_info->parent_to_child_map.empty()) {
1719 DCHECK(child_info->child_to_parent_map.empty()); 1729 DCHECK(child_info->child_to_parent_map.empty());
1720 children_.erase(child_it); 1730 children_.erase(child_it);
1721 } 1731 }
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
1977 1987
1978 const int kImportance = 2; 1988 const int kImportance = 2;
1979 pmd->CreateSharedGlobalAllocatorDump(guid); 1989 pmd->CreateSharedGlobalAllocatorDump(guid);
1980 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); 1990 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance);
1981 } 1991 }
1982 1992
1983 return true; 1993 return true;
1984 } 1994 }
1985 1995
1986 } // namespace cc 1996 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698