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/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
16 #include "gpu/command_buffer/common/constants.h" | 17 #include "gpu/command_buffer/common/constants.h" |
17 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 18 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
18 #include "gpu/command_buffer/common/sync_token.h" | 19 #include "gpu/command_buffer/common/sync_token.h" |
19 #include "gpu/command_buffer/service/buffer_manager.h" | 20 #include "gpu/command_buffer/service/buffer_manager.h" |
20 #include "gpu/command_buffer/service/command_buffer_service.h" | 21 #include "gpu/command_buffer/service/command_buffer_service.h" |
21 #include "gpu/command_buffer/service/command_executor.h" | 22 #include "gpu/command_buffer/service/command_executor.h" |
22 #include "gpu/command_buffer/service/context_group.h" | 23 #include "gpu/command_buffer/service/context_group.h" |
23 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 24 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
24 #include "gpu/command_buffer/service/logger.h" | 25 #include "gpu/command_buffer/service/logger.h" |
25 #include "gpu/command_buffer/service/mailbox_manager_impl.h" | 26 #include "gpu/command_buffer/service/mailbox_manager_impl.h" |
26 #include "gpu/command_buffer/service/sync_point_manager.h" | 27 #include "gpu/command_buffer/service/sync_point_manager.h" |
27 #include "gpu/command_buffer/service/transfer_buffer_manager.h" | 28 #include "gpu/command_buffer/service/transfer_buffer_manager.h" |
28 #include "ui/gfx/geometry/size.h" | 29 #include "ui/gfx/geometry/size.h" |
29 #include "ui/gl/gl_context.h" | 30 #include "ui/gl/gl_context.h" |
| 31 #include "ui/gl/gl_context_egl.h" |
30 #include "ui/gl/gl_context_stub_with_extensions.h" | 32 #include "ui/gl/gl_context_stub_with_extensions.h" |
31 #include "ui/gl/gl_image_ref_counted_memory.h" | 33 #include "ui/gl/gl_image_ref_counted_memory.h" |
32 #include "ui/gl/gl_share_group.h" | 34 #include "ui/gl/gl_share_group.h" |
33 #include "ui/gl/gl_stub_api.h" | 35 #include "ui/gl/gl_stub_api.h" |
34 #include "ui/gl/gl_surface.h" | 36 #include "ui/gl/gl_surface.h" |
| 37 #include "ui/gl/gl_surface_egl.h" |
35 #include "ui/gl/gl_surface_stub.h" | 38 #include "ui/gl/gl_surface_stub.h" |
36 #include "ui/gl/init/gl_factory.h" | 39 #include "ui/gl/init/gl_factory.h" |
37 #include "ui/gl/test/gl_surface_test_support.h" | 40 #include "ui/gl/test/gl_surface_test_support.h" |
38 | 41 |
39 namespace gpu { | 42 namespace gpu { |
40 namespace { | 43 namespace { |
41 | 44 |
42 const size_t kCommandBufferSize = 16384; | 45 const size_t kCommandBufferSize = 16384; |
43 const size_t kTransferBufferSize = 16384; | 46 const size_t kTransferBufferSize = 16384; |
44 const size_t kSmallTransferBufferSize = 16; | 47 const size_t kSmallTransferBufferSize = 16; |
45 const size_t kTinyTransferBufferSize = 3; | 48 const size_t kTinyTransferBufferSize = 3; |
46 | 49 |
| 50 #if !defined(GPU_FUZZER_USE_ANGLE) |
47 static const char kExtensions[] = | 51 static const char kExtensions[] = |
48 "GL_AMD_compressed_ATC_texture " | 52 "GL_AMD_compressed_ATC_texture " |
49 "GL_ANGLE_texture_compression_dxt3 " | 53 "GL_ANGLE_texture_compression_dxt3 " |
50 "GL_ANGLE_texture_compression_dxt5 " | 54 "GL_ANGLE_texture_compression_dxt5 " |
51 "GL_ANGLE_texture_usage " | 55 "GL_ANGLE_texture_usage " |
52 "GL_APPLE_ycbcr_422 " | 56 "GL_APPLE_ycbcr_422 " |
53 "GL_ARB_texture_rectangle " | 57 "GL_ARB_texture_rectangle " |
54 "GL_EXT_blend_func_extended " | 58 "GL_EXT_blend_func_extended " |
55 "GL_EXT_color_buffer_float " | 59 "GL_EXT_color_buffer_float " |
56 "GL_EXT_disjoint_timer_query " | 60 "GL_EXT_disjoint_timer_query " |
(...skipping 14 matching lines...) Expand all Loading... |
71 "GL_NV_framebuffer_mixed_samples " | 75 "GL_NV_framebuffer_mixed_samples " |
72 "GL_NV_path_rendering " | 76 "GL_NV_path_rendering " |
73 "GL_OES_compressed_ETC1_RGB8_texture " | 77 "GL_OES_compressed_ETC1_RGB8_texture " |
74 "GL_OES_depth24 " | 78 "GL_OES_depth24 " |
75 "GL_OES_EGL_image_external " | 79 "GL_OES_EGL_image_external " |
76 "GL_OES_rgb8_rgba8 " | 80 "GL_OES_rgb8_rgba8 " |
77 "GL_OES_texture_float " | 81 "GL_OES_texture_float " |
78 "GL_OES_texture_float_linear " | 82 "GL_OES_texture_float_linear " |
79 "GL_OES_texture_half_float " | 83 "GL_OES_texture_half_float " |
80 "GL_OES_texture_half_float_linear"; | 84 "GL_OES_texture_half_float_linear"; |
| 85 #endif |
81 | 86 |
82 class CommandBufferSetup { | 87 class CommandBufferSetup { |
83 public: | 88 public: |
84 CommandBufferSetup() | 89 CommandBufferSetup() |
85 : atexit_manager_(), | 90 : atexit_manager_(), |
86 sync_point_manager_(new SyncPointManager(false)), | 91 sync_point_manager_(new SyncPointManager(false)), |
87 sync_point_order_data_(SyncPointOrderData::Create()), | 92 sync_point_order_data_(SyncPointOrderData::Create()), |
88 mailbox_manager_(new gles2::MailboxManagerImpl), | 93 mailbox_manager_(new gles2::MailboxManagerImpl), |
89 share_group_(new gl::GLShareGroup), | 94 share_group_(new gl::GLShareGroup), |
90 surface_(new gl::GLSurfaceStub), | |
91 context_(new gl::GLContextStub(share_group_.get())), | |
92 command_buffer_id_(CommandBufferId::FromUnsafeValue(1)) { | 95 command_buffer_id_(CommandBufferId::FromUnsafeValue(1)) { |
93 logging::SetMinLogLevel(logging::LOG_FATAL); | 96 logging::SetMinLogLevel(logging::LOG_FATAL); |
94 base::CommandLine::Init(0, NULL); | 97 base::CommandLine::Init(0, NULL); |
95 | 98 |
| 99 #if defined(GPU_FUZZER_USE_ANGLE) |
| 100 auto* command_line = base::CommandLine::ForCurrentProcess(); |
| 101 command_line->AppendSwitchASCII(switches::kUseGL, |
| 102 gl::kGLImplementationANGLEName); |
| 103 command_line->AppendSwitchASCII(switches::kUseANGLE, |
| 104 gl::kANGLEImplementationNullName); |
| 105 gl::init::InitializeGLOneOffImplementation(gl::kGLImplementationEGLGLES2, |
| 106 false, false, false); |
| 107 surface_ = new gl::PbufferGLSurfaceEGL(gfx::Size()); |
| 108 surface_->Initialize(); |
| 109 |
| 110 context_ = new gl::GLContextEGL(share_group_.get()); |
| 111 context_->Initialize(surface_.get(), gl::GLContextAttribs()); |
| 112 #else |
| 113 surface_ = new gl::GLSurfaceStub; |
| 114 context_ = new gl::GLContextStub(share_group_.get()); |
96 gl::GLSurfaceTestSupport::InitializeOneOffWithMockBindings(); | 115 gl::GLSurfaceTestSupport::InitializeOneOffWithMockBindings(); |
97 | 116 |
98 api_.set_version("OpenGL ES 3.1"); | 117 api_ = base::MakeUnique<gl::GLStubApi>(); |
99 api_.set_extensions(kExtensions); | 118 api_->set_version("OpenGL ES 3.1"); |
100 gl::SetStubGLApi(&api_); | 119 api_->set_extensions(kExtensions); |
| 120 gl::SetStubGLApi(api_.get()); |
| 121 #endif |
101 | 122 |
102 sync_point_client_ = sync_point_manager_->CreateSyncPointClient( | 123 sync_point_client_ = sync_point_manager_->CreateSyncPointClient( |
103 sync_point_order_data_, CommandBufferNamespace::IN_PROCESS, | 124 sync_point_order_data_, CommandBufferNamespace::IN_PROCESS, |
104 command_buffer_id_); | 125 command_buffer_id_); |
105 | 126 |
106 translator_cache_ = new gles2::ShaderTranslatorCache(gpu_preferences_); | 127 translator_cache_ = new gles2::ShaderTranslatorCache(gpu_preferences_); |
107 completeness_cache_ = new gles2::FramebufferCompletenessCache; | 128 completeness_cache_ = new gles2::FramebufferCompletenessCache; |
108 } | 129 } |
109 | 130 |
110 void InitDecoder() { | 131 void InitDecoder() { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 // reasonably sized buffer in slot 4 allows us to prime the corpus with data | 272 // reasonably sized buffer in slot 4 allows us to prime the corpus with data |
252 // extracted from unit tests. | 273 // extracted from unit tests. |
253 CreateTransferBuffer(kTransferBufferSize, 2); | 274 CreateTransferBuffer(kTransferBufferSize, 2); |
254 CreateTransferBuffer(kSmallTransferBufferSize, 3); | 275 CreateTransferBuffer(kSmallTransferBufferSize, 3); |
255 CreateTransferBuffer(kTransferBufferSize, 4); | 276 CreateTransferBuffer(kTransferBufferSize, 4); |
256 CreateTransferBuffer(kTinyTransferBufferSize, 5); | 277 CreateTransferBuffer(kTinyTransferBufferSize, 5); |
257 } | 278 } |
258 | 279 |
259 base::AtExitManager atexit_manager_; | 280 base::AtExitManager atexit_manager_; |
260 | 281 |
261 gl::GLStubApi api_; | |
262 GpuPreferences gpu_preferences_; | 282 GpuPreferences gpu_preferences_; |
263 | 283 |
264 std::unique_ptr<SyncPointManager> sync_point_manager_; | 284 std::unique_ptr<SyncPointManager> sync_point_manager_; |
265 scoped_refptr<SyncPointOrderData> sync_point_order_data_; | 285 scoped_refptr<SyncPointOrderData> sync_point_order_data_; |
266 std::unique_ptr<SyncPointClient> sync_point_client_; | 286 std::unique_ptr<SyncPointClient> sync_point_client_; |
267 scoped_refptr<gles2::MailboxManager> mailbox_manager_; | 287 scoped_refptr<gles2::MailboxManager> mailbox_manager_; |
268 scoped_refptr<gl::GLShareGroup> share_group_; | 288 scoped_refptr<gl::GLShareGroup> share_group_; |
| 289 const gpu::CommandBufferId command_buffer_id_; |
| 290 |
269 scoped_refptr<gl::GLSurface> surface_; | 291 scoped_refptr<gl::GLSurface> surface_; |
270 scoped_refptr<gl::GLContext> context_; | 292 scoped_refptr<gl::GLContext> context_; |
271 const gpu::CommandBufferId command_buffer_id_; | 293 #if !defined(GPU_FUZZER_USE_ANGLE) |
| 294 std::unique_ptr<gl::GLStubApi> api_; |
| 295 #endif |
272 | 296 |
273 scoped_refptr<gles2::ShaderTranslatorCache> translator_cache_; | 297 scoped_refptr<gles2::ShaderTranslatorCache> translator_cache_; |
274 scoped_refptr<gles2::FramebufferCompletenessCache> completeness_cache_; | 298 scoped_refptr<gles2::FramebufferCompletenessCache> completeness_cache_; |
275 | 299 |
276 std::unique_ptr<CommandBufferService> command_buffer_; | 300 std::unique_ptr<CommandBufferService> command_buffer_; |
277 | 301 |
278 std::unique_ptr<gles2::GLES2Decoder> decoder_; | 302 std::unique_ptr<gles2::GLES2Decoder> decoder_; |
279 std::unique_ptr<CommandExecutor> executor_; | 303 std::unique_ptr<CommandExecutor> executor_; |
280 | 304 |
281 scoped_refptr<gles2::ShaderTranslatorInterface> vertex_translator_; | 305 scoped_refptr<gles2::ShaderTranslatorInterface> vertex_translator_; |
282 scoped_refptr<gles2::ShaderTranslatorInterface> fragment_translator_; | 306 scoped_refptr<gles2::ShaderTranslatorInterface> fragment_translator_; |
283 | 307 |
284 scoped_refptr<Buffer> buffer_; | 308 scoped_refptr<Buffer> buffer_; |
285 int32_t buffer_id_ = 0; | 309 int32_t buffer_id_ = 0; |
286 }; | 310 }; |
287 | 311 |
| 312 // Intentionally leaked because asan tries to exit cleanly after a crash, but |
| 313 // the decoder is usually in a bad state at that point. |
| 314 // We need to load ANGLE libraries before the fuzzer infrastructure starts, |
| 315 // because it gets confused about new coverage counters being dynamically |
| 316 // registered, causing crashes. |
| 317 CommandBufferSetup* g_setup = new CommandBufferSetup(); |
| 318 |
288 } // anonymous namespace | 319 } // anonymous namespace |
289 } // namespace gpu | 320 } // namespace gpu |
290 | 321 |
291 | |
292 static gpu::CommandBufferSetup& GetSetup() { | |
293 static gpu::CommandBufferSetup setup; | |
294 return setup; | |
295 } | |
296 | |
297 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | 322 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
298 GetSetup().RunCommandBuffer(data, size); | 323 gpu::g_setup->RunCommandBuffer(data, size); |
299 return 0; | 324 return 0; |
300 } | 325 } |
OLD | NEW |