Skip to content

Commit

Permalink
Rework RasterInterface::CopySubTexture
Browse files Browse the repository at this point in the history
Pass mailboxes directyl instead of requiring CreateAndConsumeTexture +
DeleteTextures.
Simplify CreateAndConsumeTexture and DeleteTextures that are now only
used for GPU Raster.
Remove tracking structures in RasterDecoder and RasterImplementation*
which become entirely unnecessary.

Bug: 829435

Change-Id: I73c3155932fd417b4f95dd99e7fe8e3511685d61
Reviewed-on: https://chromium-review.googlesource.com/c/1407259
Reviewed-by: Jonathan Backer <backer@chromium.org>
Commit-Queue: Antoine Labour <piman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#622636}
  • Loading branch information
pimanttr authored and Commit Bot committed Jan 14, 2019
1 parent 1cc7d19 commit 0da6685
Show file tree
Hide file tree
Showing 28 changed files with 334 additions and 653 deletions.
6 changes: 2 additions & 4 deletions cc/raster/gpu_raster_buffer_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,7 @@ static void RasterizeSource(
// valid by the time the consume command executes.
ri->WaitSyncTokenCHROMIUM(sync_token.GetConstData());
}
GLuint texture_id = ri->CreateAndConsumeTexture(
texture_is_overlay_candidate, gfx::BufferUsage::SCANOUT, resource_format,
mailbox->name);
GLuint texture_id = ri->CreateAndConsumeForGpuRaster(mailbox->name);
{
ScopedGrContextAccess gr_context_access(context_provider);
base::Optional<viz::ClientResourceProvider::ScopedSkSurface> scoped_surface;
Expand Down Expand Up @@ -242,7 +240,7 @@ static void RasterizeSource(
playback_settings);
}

ri->DeleteTextures(1, &texture_id);
ri->DeleteGpuRasterTexture(texture_id);
}

} // namespace
Expand Down
14 changes: 3 additions & 11 deletions cc/raster/one_copy_raster_buffer_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -404,12 +404,6 @@ gpu::SyncToken OneCopyRasterBufferProvider::CopyOnWorkerThread(
DCHECK(ri);
ri->WaitSyncTokenCHROMIUM(sync_token.GetConstData());
ri->WaitSyncTokenCHROMIUM(sii->GenUnverifiedSyncToken().GetConstData());
GLuint mailbox_texture_id = ri->CreateAndConsumeTexture(
mailbox_texture_is_overlay_candidate, gfx::BufferUsage::SCANOUT,
resource_format, mailbox->name);
GLuint staging_texture_id = ri->CreateAndConsumeTexture(
true, StagingBufferUsage(), staging_buffer->format,
staging_buffer->mailbox.name);

// Do not use queries unless COMMANDS_COMPLETED queries are supported, or
// COMMANDS_ISSUED queries are sufficient.
Expand Down Expand Up @@ -456,8 +450,9 @@ gpu::SyncToken OneCopyRasterBufferProvider::CopyOnWorkerThread(
int rows_to_copy = std::min(chunk_size_in_rows, height - y);
DCHECK_GT(rows_to_copy, 0);

ri->CopySubTexture(staging_texture_id, mailbox_texture_id, 0, y, 0, y,
rect_to_copy.width(), rows_to_copy);
ri->CopySubTexture(staging_buffer->mailbox, *mailbox,
mailbox_texture_target, 0, y, 0, y, rect_to_copy.width(),
rows_to_copy);
y += rows_to_copy;

// Increment |bytes_scheduled_since_last_flush_| by the amount of memory
Expand All @@ -473,9 +468,6 @@ gpu::SyncToken OneCopyRasterBufferProvider::CopyOnWorkerThread(
if (query_target != GL_NONE)
ri->EndQueryEXT(query_target);

GLuint textures_to_delete[] = {mailbox_texture_id, staging_texture_id};
ri->DeleteTextures(2, textures_to_delete);

// Generate sync token on the worker context that will be sent to and waited
// for by the display compositor before using the content generated here.
// The same sync token is used to synchronize operations on the staging
Expand Down
2 changes: 1 addition & 1 deletion cc/raster/raster_buffer_provider_perftest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class PerfContextProvider
capabilities_.sync_query = true;

raster_context_ = std::make_unique<gpu::raster::RasterImplementationGLES>(
context_gl_.get(), capabilities_);
context_gl_.get());
}

// viz::ContextProvider implementation.
Expand Down
3 changes: 1 addition & 2 deletions cc/test/test_in_process_context_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ gpu::ContextResult TestInProcessContextProvider::BindToCurrentThread() {
base::ThreadTaskRunnerHandle::Get()));
raster_implementation_gles2_ =
std::make_unique<gpu::raster::RasterImplementationGLES>(
gles2_context_->GetImplementation(),
gles2_context_->GetCapabilities());
gles2_context_->GetImplementation());
}

cache_controller_->SetLock(GetLock());
Expand Down
2 changes: 1 addition & 1 deletion components/viz/test/test_context_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ TestContextProvider::TestContextProvider(
context_thread_checker_.DetachFromThread();
context_gl_->set_test_support(support_.get());
raster_context_ = std::make_unique<gpu::raster::RasterImplementationGLES>(
context_gl_.get(), context_gl_->test_capabilities());
context_gl_.get());
// Just pass nullptr to the ContextCacheController for its task runner.
// Idle handling is tested directly in ContextCacheController's
// unittests, and isn't needed here.
Expand Down
13 changes: 6 additions & 7 deletions gpu/command_buffer/build_raster_cmd_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,6 @@
# not_shared: For GENn types, True if objects can't be shared between contexts

_FUNCTION_INFO = {
'CreateAndConsumeTexture': {
'type': 'NoCommand',
'trace_level': 2,
},
'CreateAndConsumeTextureINTERNAL': {
'decoder_func': 'DoCreateAndConsumeTextureINTERNAL',
'internal': True,
Expand All @@ -193,15 +189,18 @@
'unit_test': False,
'trace_level': 2,
},
'CopySubTexture': {
'decoder_func': 'DoCopySubTexture',
'CopySubTextureINTERNAL': {
'decoder_func': 'DoCopySubTextureINTERNAL',
'internal': True,
'unit_test': False,
'trace_level': 2,
},
'DeleteTextures': {
'DeleteTexturesINTERNAL': {
'type': 'DELn',
'internal': True,
'resource_type': 'Texture',
'resource_types': 'Textures',
'unit_test': False,
},
'Finish': {
'impl_func': False,
Expand Down
45 changes: 22 additions & 23 deletions gpu/command_buffer/client/raster_cmd_helper_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@
#ifndef GPU_COMMAND_BUFFER_CLIENT_RASTER_CMD_HELPER_AUTOGEN_H_
#define GPU_COMMAND_BUFFER_CLIENT_RASTER_CMD_HELPER_AUTOGEN_H_

void DeleteTexturesImmediate(GLsizei n, const GLuint* textures) {
const uint32_t size = raster::cmds::DeleteTexturesImmediate::ComputeSize(n);
raster::cmds::DeleteTexturesImmediate* c =
GetImmediateCmdSpaceTotalSize<raster::cmds::DeleteTexturesImmediate>(
size);
if (c) {
c->Init(n, textures);
}
}

void Finish() {
raster::cmds::Finish* c = GetCmdSpace<raster::cmds::Finish>();
if (c) {
Expand Down Expand Up @@ -193,34 +183,43 @@ void ClearPaintCacheINTERNAL() {
}

void CreateAndConsumeTextureINTERNALImmediate(GLuint texture_id,
bool use_buffer,
gfx::BufferUsage buffer_usage,
viz::ResourceFormat format,
const GLbyte* mailbox) {
const uint32_t size =
raster::cmds::CreateAndConsumeTextureINTERNALImmediate::ComputeSize();
raster::cmds::CreateAndConsumeTextureINTERNALImmediate* c =
GetImmediateCmdSpaceTotalSize<
raster::cmds::CreateAndConsumeTextureINTERNALImmediate>(size);
if (c) {
c->Init(texture_id, use_buffer, buffer_usage, format, mailbox);
c->Init(texture_id, mailbox);
}
}

void CopySubTexture(GLuint source_id,
GLuint dest_id,
GLint xoffset,
GLint yoffset,
GLint x,
GLint y,
GLsizei width,
GLsizei height) {
raster::cmds::CopySubTexture* c = GetCmdSpace<raster::cmds::CopySubTexture>();
void CopySubTextureINTERNAL(GLuint source_id,
GLuint dest_id,
GLint xoffset,
GLint yoffset,
GLint x,
GLint y,
GLsizei width,
GLsizei height) {
raster::cmds::CopySubTextureINTERNAL* c =
GetCmdSpace<raster::cmds::CopySubTextureINTERNAL>();
if (c) {
c->Init(source_id, dest_id, xoffset, yoffset, x, y, width, height);
}
}

void DeleteTexturesINTERNALImmediate(GLsizei n, const GLuint* textures) {
const uint32_t size =
raster::cmds::DeleteTexturesINTERNALImmediate::ComputeSize(n);
raster::cmds::DeleteTexturesINTERNALImmediate* c =
GetImmediateCmdSpaceTotalSize<
raster::cmds::DeleteTexturesINTERNALImmediate>(size);
if (c) {
c->Init(n, textures);
}
}

void TraceBeginCHROMIUM(GLuint category_bucket_id, GLuint name_bucket_id) {
raster::cmds::TraceBeginCHROMIUM* c =
GetCmdSpace<raster::cmds::TraceBeginCHROMIUM>();
Expand Down
93 changes: 43 additions & 50 deletions gpu/command_buffer/client/raster_implementation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ RasterImplementation::RasterImplementation(
ImageDecodeAcceleratorInterface* image_decode_accelerator)
: ImplementationBase(helper, transfer_buffer, gpu_control),
helper_(helper),
active_texture_unit_(0),
error_bits_(0),
lose_context_when_out_of_memory_(lose_context_when_out_of_memory),
use_count_(0),
Expand Down Expand Up @@ -325,9 +324,6 @@ gpu::ContextResult RasterImplementation::Initialize(
return result;
}

texture_units_ = std::make_unique<TextureUnit[]>(
capabilities_.max_combined_texture_image_units);

return gpu::ContextResult::kSuccess;
}

Expand All @@ -349,15 +345,8 @@ RasterCmdHelper* RasterImplementation::helper() const {
}

IdAllocator* RasterImplementation::GetIdAllocator(IdNamespaces namespace_id) {
switch (namespace_id) {
case IdNamespaces::kQueries:
return &query_id_allocator_;
case IdNamespaces::kTextures:
return &texture_id_allocator_;
default:
DCHECK(false);
return nullptr;
}
DCHECK_EQ(namespace_id, IdNamespaces::kQueries);
return &query_id_allocator_;
}

void RasterImplementation::OnGpuControlLostContext() {
Expand Down Expand Up @@ -783,28 +772,6 @@ void RasterImplementation::FinishHelper() {
void RasterImplementation::GenQueriesEXTHelper(GLsizei /* n */,
const GLuint* /* queries */) {}

void RasterImplementation::DeleteTexturesHelper(GLsizei n,
const GLuint* textures) {
helper_->DeleteTexturesImmediate(n, textures);
for (GLsizei ii = 0; ii < n; ++ii) {
texture_id_allocator_.FreeID(textures[ii]);
}
UnbindTexturesHelper(n, textures);
}

void RasterImplementation::UnbindTexturesHelper(GLsizei n,
const GLuint* textures) {
for (GLsizei ii = 0; ii < n; ++ii) {
for (GLint tt = 0; tt < capabilities_.max_combined_texture_image_units;
++tt) {
TextureUnit& unit = texture_units_[tt];
if (textures[ii] == unit.bound_texture_2d) {
unit.bound_texture_2d = 0;
}
}
}
}

GLenum RasterImplementation::GetGraphicsResetStatusKHR() {
GPU_CLIENT_SINGLE_THREAD_CHECK();
GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glGetGraphicsResetStatusKHR()");
Expand Down Expand Up @@ -1040,23 +1007,39 @@ void RasterImplementation::UnmapRasterCHROMIUM(uint32_t raster_written_size,
// instead of having to edit some template or the code generator.
#include "gpu/command_buffer/client/raster_implementation_impl_autogen.h"

GLuint RasterImplementation::CreateAndConsumeTexture(
bool use_buffer,
gfx::BufferUsage buffer_usage,
viz::ResourceFormat format,
const GLbyte* mailbox) {
void RasterImplementation::CopySubTexture(const gpu::Mailbox& source_mailbox,
const gpu::Mailbox& dest_mailbox,
GLenum dest_target,
GLint xoffset,
GLint yoffset,
GLint x,
GLint y,
GLsizei width,
GLsizei height) {
GPU_CLIENT_SINGLE_THREAD_CHECK();
GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glCreateAndConsumeTexture("
<< use_buffer << ", "
<< static_cast<uint32_t>(buffer_usage) << ", "
<< static_cast<uint32_t>(format) << ", "
<< static_cast<const void*>(mailbox) << ")");
GLuint client_id = texture_id_allocator_.AllocateID();
helper_->CreateAndConsumeTextureINTERNALImmediate(
client_id, use_buffer, buffer_usage, format, mailbox);
GPU_CLIENT_LOG("returned " << client_id);
GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glCopySubTexture("
<< source_mailbox.ToDebugString() << ", "
<< dest_mailbox.ToDebugString() << ", " << xoffset << ", "
<< yoffset << ", " << x << ", " << y << ", " << width
<< ", " << height << ")");
if (width < 0) {
SetGLError(GL_INVALID_VALUE, "glCopySubTexture", "width < 0");
return;
}
if (height < 0) {
SetGLError(GL_INVALID_VALUE, "glCopySubTexture", "height < 0");
return;
}
// TODO(piman): coalesce all these commands.
GLuint texture_ids[2] = {1, 2};
helper_->CreateAndConsumeTextureINTERNALImmediate(texture_ids[0],
source_mailbox.name);
helper_->CreateAndConsumeTextureINTERNALImmediate(texture_ids[1],
dest_mailbox.name);
helper_->CopySubTextureINTERNAL(texture_ids[0], texture_ids[1], xoffset,
yoffset, x, y, width, height);
helper_->DeleteTexturesINTERNALImmediate(2, texture_ids);
CheckGLError();
return client_id;
}

void RasterImplementation::BeginRasterCHROMIUM(
Expand Down Expand Up @@ -1202,6 +1185,16 @@ void RasterImplementation::IssueImageDecodeCacheEntryCreation(
target_color_space, needs_mips);
}

GLuint RasterImplementation::CreateAndConsumeForGpuRaster(
const GLbyte* mailbox) {
NOTREACHED();
return 0;
}

void RasterImplementation::DeleteGpuRasterTexture(GLuint texture) {
NOTREACHED();
}

void RasterImplementation::BeginGpuRaster() {
NOTREACHED();
}
Expand Down
19 changes: 12 additions & 7 deletions gpu/command_buffer/client/raster_implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ class RASTER_EXPORT RasterImplementation : public RasterInterface,
#include "gpu/command_buffer/client/raster_implementation_autogen.h"

// RasterInterface implementation.
void CopySubTexture(const gpu::Mailbox& source_mailbox,
const gpu::Mailbox& dest_mailbox,
GLenum dest_target,
GLint xoffset,
GLint yoffset,
GLint x,
GLint y,
GLsizei width,
GLsizei height) override;

void BeginRasterCHROMIUM(GLuint sk_color,
GLuint msaa_sample_count,
GLboolean can_use_lcd_text,
Expand All @@ -129,6 +139,8 @@ class RASTER_EXPORT RasterImplementation : public RasterInterface,
uint32_t transfer_cache_entry_id,
const gfx::ColorSpace& target_color_space,
bool needs_mips) override;
GLuint CreateAndConsumeForGpuRaster(const GLbyte* mailbox) override;
void DeleteGpuRasterTexture(GLuint texture) override;
void BeginGpuRaster() override;
void EndGpuRaster() override;

Expand Down Expand Up @@ -244,7 +256,6 @@ class RASTER_EXPORT RasterImplementation : public RasterInterface,
void GenQueriesEXTHelper(GLsizei n, const GLuint* queries);

void DeleteTexturesHelper(GLsizei n, const GLuint* textures);
void UnbindTexturesHelper(GLsizei n, const GLuint* textures);
void DeleteQueriesEXTHelper(GLsizei n, const GLuint* queries);

// IdAllocators for objects that can't be shared among contexts.
Expand Down Expand Up @@ -291,11 +302,6 @@ class RASTER_EXPORT RasterImplementation : public RasterInterface,
gles2::DebugMarkerManager debug_marker_manager_;
std::string this_in_hex_;

std::unique_ptr<TextureUnit[]> texture_units_;

// 0 to capabilities_.max_combined_texture_image_units.
GLuint active_texture_unit_;

// Current GL error bits.
uint32_t error_bits_;

Expand All @@ -318,7 +324,6 @@ class RASTER_EXPORT RasterImplementation : public RasterInterface,
// whether it should aggressively free them.
bool aggressively_free_resources_;

IdAllocator texture_id_allocator_;
IdAllocator query_id_allocator_;

ClientFontManager font_manager_;
Expand Down
Loading

0 comments on commit 0da6685

Please sign in to comment.