OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include <stddef.h> | 4 #include <stddef.h> |
5 #include <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "gpu/command_buffer/common/constants.h" | 17 #include "gpu/command_buffer/common/constants.h" |
18 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 18 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
19 #include "gpu/command_buffer/common/sync_token.h" | 19 #include "gpu/command_buffer/common/sync_token.h" |
20 #include "gpu/command_buffer/service/buffer_manager.h" | 20 #include "gpu/command_buffer/service/buffer_manager.h" |
21 #include "gpu/command_buffer/service/command_buffer_service.h" | 21 #include "gpu/command_buffer/service/command_buffer_service.h" |
22 #include "gpu/command_buffer/service/command_executor.h" | 22 #include "gpu/command_buffer/service/command_executor.h" |
23 #include "gpu/command_buffer/service/context_group.h" | 23 #include "gpu/command_buffer/service/context_group.h" |
24 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 24 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 25 #include "gpu/command_buffer/service/gpu_switches.h" |
25 #include "gpu/command_buffer/service/logger.h" | 26 #include "gpu/command_buffer/service/logger.h" |
26 #include "gpu/command_buffer/service/mailbox_manager_impl.h" | 27 #include "gpu/command_buffer/service/mailbox_manager_impl.h" |
27 #include "gpu/command_buffer/service/sync_point_manager.h" | 28 #include "gpu/command_buffer/service/sync_point_manager.h" |
28 #include "gpu/command_buffer/service/transfer_buffer_manager.h" | 29 #include "gpu/command_buffer/service/transfer_buffer_manager.h" |
29 #include "ui/gfx/geometry/size.h" | 30 #include "ui/gfx/geometry/size.h" |
30 #include "ui/gl/gl_context.h" | 31 #include "ui/gl/gl_context.h" |
31 #include "ui/gl/gl_context_egl.h" | 32 #include "ui/gl/gl_context_egl.h" |
32 #include "ui/gl/gl_context_stub.h" | 33 #include "ui/gl/gl_context_stub.h" |
33 #include "ui/gl/gl_image_ref_counted_memory.h" | 34 #include "ui/gl/gl_image_ref_counted_memory.h" |
34 #include "ui/gl/gl_share_group.h" | 35 #include "ui/gl/gl_share_group.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 CommandBufferSetup() | 90 CommandBufferSetup() |
90 : atexit_manager_(), | 91 : atexit_manager_(), |
91 sync_point_manager_(new SyncPointManager()), | 92 sync_point_manager_(new SyncPointManager()), |
92 sync_point_order_data_(SyncPointOrderData::Create()), | 93 sync_point_order_data_(SyncPointOrderData::Create()), |
93 mailbox_manager_(new gles2::MailboxManagerImpl), | 94 mailbox_manager_(new gles2::MailboxManagerImpl), |
94 share_group_(new gl::GLShareGroup), | 95 share_group_(new gl::GLShareGroup), |
95 command_buffer_id_(CommandBufferId::FromUnsafeValue(1)) { | 96 command_buffer_id_(CommandBufferId::FromUnsafeValue(1)) { |
96 logging::SetMinLogLevel(logging::LOG_FATAL); | 97 logging::SetMinLogLevel(logging::LOG_FATAL); |
97 base::CommandLine::Init(0, NULL); | 98 base::CommandLine::Init(0, NULL); |
98 | 99 |
| 100 auto* command_line = base::CommandLine::ForCurrentProcess(); |
| 101 ALLOW_UNUSED_LOCAL(command_line); |
| 102 |
| 103 #if defined(GPU_FUZZER_USE_PASSTHROUGH_CMD_DECODER) |
| 104 command_line->AppendSwitch(switches::kUsePassthroughCmdDecoder); |
| 105 gpu_preferences_.use_passthrough_cmd_decoder = true; |
| 106 recreate_context_ = true; |
| 107 #endif |
| 108 |
99 #if defined(GPU_FUZZER_USE_ANGLE) | 109 #if defined(GPU_FUZZER_USE_ANGLE) |
100 auto* command_line = base::CommandLine::ForCurrentProcess(); | |
101 command_line->AppendSwitchASCII(switches::kUseGL, | 110 command_line->AppendSwitchASCII(switches::kUseGL, |
102 gl::kGLImplementationANGLEName); | 111 gl::kGLImplementationANGLEName); |
103 command_line->AppendSwitchASCII(switches::kUseANGLE, | 112 command_line->AppendSwitchASCII(switches::kUseANGLE, |
104 gl::kANGLEImplementationNullName); | 113 gl::kANGLEImplementationNullName); |
105 gl::init::InitializeGLOneOffImplementation(gl::kGLImplementationEGLGLES2, | 114 gl::init::InitializeGLOneOffImplementation(gl::kGLImplementationEGLGLES2, |
106 false, false, false); | 115 false, false, false); |
| 116 |
107 surface_ = new gl::PbufferGLSurfaceEGL(gfx::Size()); | 117 surface_ = new gl::PbufferGLSurfaceEGL(gfx::Size()); |
108 surface_->Initialize(); | 118 surface_->Initialize(); |
109 | 119 if (!recreate_context_) { |
110 context_ = new gl::GLContextEGL(share_group_.get()); | 120 InitContext(); |
111 context_->Initialize(surface_.get(), gl::GLContextAttribs()); | 121 } |
112 #else | 122 #else |
113 surface_ = new gl::GLSurfaceStub; | 123 surface_ = new gl::GLSurfaceStub; |
114 scoped_refptr<gl::GLContextStub> context_stub = | 124 InitContext(); |
115 new gl::GLContextStub(share_group_.get()); | |
116 context_stub->SetGLVersionString("OpenGL ES 3.1"); | |
117 context_stub->SetExtensionsString(kExtensions); | |
118 context_stub->SetUseStubApi(true); | |
119 context_ = context_stub; | |
120 gl::GLSurfaceTestSupport::InitializeOneOffWithMockBindings(); | 125 gl::GLSurfaceTestSupport::InitializeOneOffWithMockBindings(); |
121 #endif | 126 #endif |
122 | 127 |
123 sync_point_client_ = base::MakeUnique<SyncPointClient>( | 128 sync_point_client_ = base::MakeUnique<SyncPointClient>( |
124 sync_point_manager_.get(), sync_point_order_data_, | 129 sync_point_manager_.get(), sync_point_order_data_, |
125 CommandBufferNamespace::IN_PROCESS, command_buffer_id_); | 130 CommandBufferNamespace::IN_PROCESS, command_buffer_id_); |
126 | 131 |
127 translator_cache_ = new gles2::ShaderTranslatorCache(gpu_preferences_); | 132 translator_cache_ = new gles2::ShaderTranslatorCache(gpu_preferences_); |
128 completeness_cache_ = new gles2::FramebufferCompletenessCache; | 133 completeness_cache_ = new gles2::FramebufferCompletenessCache; |
129 } | 134 } |
130 | 135 |
131 void InitDecoder() { | 136 void InitDecoder() { |
| 137 if (recreate_context_) { |
| 138 InitContext(); |
| 139 } |
| 140 |
132 context_->MakeCurrent(surface_.get()); | 141 context_->MakeCurrent(surface_.get()); |
133 scoped_refptr<gles2::FeatureInfo> feature_info = | 142 scoped_refptr<gles2::FeatureInfo> feature_info = |
134 new gles2::FeatureInfo(); | 143 new gles2::FeatureInfo(); |
135 scoped_refptr<gles2::ContextGroup> context_group = new gles2::ContextGroup( | 144 scoped_refptr<gles2::ContextGroup> context_group = new gles2::ContextGroup( |
136 gpu_preferences_, mailbox_manager_.get(), nullptr, translator_cache_, | 145 gpu_preferences_, mailbox_manager_.get(), nullptr, translator_cache_, |
137 completeness_cache_, feature_info, true /* bind_generates_resource */, | 146 completeness_cache_, feature_info, true /* bind_generates_resource */, |
138 nullptr /* image_factory */, nullptr /* progress_reporter */, | 147 nullptr /* image_factory */, nullptr /* progress_reporter */, |
139 GpuFeatureInfo()); | 148 GpuFeatureInfo()); |
140 command_buffer_.reset( | 149 command_buffer_.reset( |
141 new CommandBufferService(context_group->transfer_buffer_manager())); | 150 new CommandBufferService(context_group->transfer_buffer_manager())); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 if (!vertex_translator_) { | 183 if (!vertex_translator_) { |
175 // Keep a reference to the translators, which keeps them in the cache even | 184 // Keep a reference to the translators, which keeps them in the cache even |
176 // after the decoder is reset. They are expensive to initialize, but they | 185 // after the decoder is reset. They are expensive to initialize, but they |
177 // don't keep state. | 186 // don't keep state. |
178 vertex_translator_ = decoder_->GetTranslator(GL_VERTEX_SHADER); | 187 vertex_translator_ = decoder_->GetTranslator(GL_VERTEX_SHADER); |
179 fragment_translator_ = decoder_->GetTranslator(GL_FRAGMENT_SHADER); | 188 fragment_translator_ = decoder_->GetTranslator(GL_FRAGMENT_SHADER); |
180 } | 189 } |
181 } | 190 } |
182 | 191 |
183 void ResetDecoder() { | 192 void ResetDecoder() { |
| 193 if (recreate_context_) { |
| 194 context_->ReleaseCurrent(nullptr); |
| 195 context_ = nullptr; |
| 196 } |
184 decoder_->Destroy(true); | 197 decoder_->Destroy(true); |
185 decoder_.reset(); | 198 decoder_.reset(); |
186 command_buffer_.reset(); | 199 command_buffer_.reset(); |
187 } | 200 } |
188 | 201 |
189 ~CommandBufferSetup() { | 202 ~CommandBufferSetup() { |
190 sync_point_client_ = nullptr; | 203 sync_point_client_ = nullptr; |
191 if (sync_point_order_data_) { | 204 if (sync_point_order_data_) { |
192 sync_point_order_data_->Destroy(); | 205 sync_point_order_data_->Destroy(); |
193 sync_point_order_data_ = nullptr; | 206 sync_point_order_data_ = nullptr; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 CHECK(buffer_); | 275 CHECK(buffer_); |
263 // Create some transfer buffers. This is somewhat arbitrary, but having a | 276 // Create some transfer buffers. This is somewhat arbitrary, but having a |
264 // reasonably sized buffer in slot 4 allows us to prime the corpus with data | 277 // reasonably sized buffer in slot 4 allows us to prime the corpus with data |
265 // extracted from unit tests. | 278 // extracted from unit tests. |
266 CreateTransferBuffer(kTransferBufferSize, 2); | 279 CreateTransferBuffer(kTransferBufferSize, 2); |
267 CreateTransferBuffer(kSmallTransferBufferSize, 3); | 280 CreateTransferBuffer(kSmallTransferBufferSize, 3); |
268 CreateTransferBuffer(kTransferBufferSize, 4); | 281 CreateTransferBuffer(kTransferBufferSize, 4); |
269 CreateTransferBuffer(kTinyTransferBufferSize, 5); | 282 CreateTransferBuffer(kTinyTransferBufferSize, 5); |
270 } | 283 } |
271 | 284 |
| 285 void InitContext() { |
| 286 #if defined(GPU_FUZZER_USE_ANGLE) |
| 287 context_ = new gl::GLContextEGL(share_group_.get()); |
| 288 context_->Initialize(surface_.get(), gl::GLContextAttribs()); |
| 289 #else |
| 290 scoped_refptr<gl::GLContextStub> context_stub = |
| 291 new gl::GLContextStub(share_group_.get()); |
| 292 context_stub->SetGLVersionString("OpenGL ES 3.1"); |
| 293 context_stub->SetExtensionsString(kExtensions); |
| 294 context_stub->SetUseStubApi(true); |
| 295 context_ = context_stub; |
| 296 #endif |
| 297 } |
| 298 |
272 base::AtExitManager atexit_manager_; | 299 base::AtExitManager atexit_manager_; |
273 | 300 |
274 GpuPreferences gpu_preferences_; | 301 GpuPreferences gpu_preferences_; |
275 | 302 |
276 std::unique_ptr<SyncPointManager> sync_point_manager_; | 303 std::unique_ptr<SyncPointManager> sync_point_manager_; |
277 scoped_refptr<SyncPointOrderData> sync_point_order_data_; | 304 scoped_refptr<SyncPointOrderData> sync_point_order_data_; |
278 std::unique_ptr<SyncPointClient> sync_point_client_; | 305 std::unique_ptr<SyncPointClient> sync_point_client_; |
279 scoped_refptr<gles2::MailboxManager> mailbox_manager_; | 306 scoped_refptr<gles2::MailboxManager> mailbox_manager_; |
280 scoped_refptr<gl::GLShareGroup> share_group_; | 307 scoped_refptr<gl::GLShareGroup> share_group_; |
281 const gpu::CommandBufferId command_buffer_id_; | 308 const gpu::CommandBufferId command_buffer_id_; |
282 | 309 |
| 310 bool recreate_context_ = false; |
283 scoped_refptr<gl::GLSurface> surface_; | 311 scoped_refptr<gl::GLSurface> surface_; |
284 scoped_refptr<gl::GLContext> context_; | 312 scoped_refptr<gl::GLContext> context_; |
285 | 313 |
286 scoped_refptr<gles2::ShaderTranslatorCache> translator_cache_; | 314 scoped_refptr<gles2::ShaderTranslatorCache> translator_cache_; |
287 scoped_refptr<gles2::FramebufferCompletenessCache> completeness_cache_; | 315 scoped_refptr<gles2::FramebufferCompletenessCache> completeness_cache_; |
288 | 316 |
289 std::unique_ptr<CommandBufferService> command_buffer_; | 317 std::unique_ptr<CommandBufferService> command_buffer_; |
290 | 318 |
291 std::unique_ptr<gles2::GLES2Decoder> decoder_; | 319 std::unique_ptr<gles2::GLES2Decoder> decoder_; |
292 std::unique_ptr<CommandExecutor> executor_; | 320 std::unique_ptr<CommandExecutor> executor_; |
(...skipping 12 matching lines...) Expand all Loading... |
305 // registered, causing crashes. | 333 // registered, causing crashes. |
306 CommandBufferSetup* g_setup = new CommandBufferSetup(); | 334 CommandBufferSetup* g_setup = new CommandBufferSetup(); |
307 | 335 |
308 } // anonymous namespace | 336 } // anonymous namespace |
309 } // namespace gpu | 337 } // namespace gpu |
310 | 338 |
311 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | 339 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
312 gpu::g_setup->RunCommandBuffer(data, size); | 340 gpu::g_setup->RunCommandBuffer(data, size); |
313 return 0; | 341 return 0; |
314 } | 342 } |
OLD | NEW |